Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
html2pdf
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Lukas Niegsch
html2pdf
Commits
84b7f17d
Commit
84b7f17d
authored
Jul 16, 2022
by
lukas.niegsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: devtools api
parent
8ec9dd1d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
25 deletions
+106
-25
gadget_devtools.html
gadget_devtools.html
+11
-11
gadget_devtools.js
gadget_devtools.js
+95
-14
No files found.
gadget_devtools.html
View file @
84b7f17d
...
...
@@ -23,10 +23,11 @@
-> BROWSER_PASSWORD="password"
Usage:
var devtools;
this.getDeclaredGadget("devtools")
.push(function (subgadget) {
devtools = subgadget;
var devtools = gadget.getDevtools()
.push(function () {
console.log(devtools.Page.description) // "..."
console.log(devtools.Page.enable.description); // "..."
console.log(devtools.Page.enable.experimental); // false
return devtools.Page.enable();
})
.push(function () {
...
...
@@ -36,13 +37,12 @@
return devtools.Page.loadEventFired();
})
The variable devtools contains this gadget. This gadget has several
subobjects according to the protocol, e.g. Page. Each subobjects has
methods and events. Both of them can be used like regular functions.
Calling a method will trigger it, and calling an event will wait
until the browser triggers it. Some methods will return some types,
which we encode as objects. See the references on how to use the
different methods, events, and types.
This devtools object has several subobjects according to the
protocol, e.g. Page. Each subobjects has methods and events. Both of
them can be used like regular functions. Calling a method will trigger
it, and calling an event will wait until the browser triggers it. Some
methods will return some types, which we encode as objects. See the
references on how to use the different methods, events, and types.
References:
https://chromedevtools.github.io/devtools-protocol
...
...
gadget_devtools.js
View file @
84b7f17d
...
...
@@ -6,7 +6,7 @@ var BROWSER_PASSWORD = "ignored";
(
function
(
window
,
rJS
,
RSVP
)
{
"
use strict
"
;
/**
* Makes an HTTP
get
request to the browser to retrieve some JSON data.
* Makes an HTTP
GET
request to the browser to retrieve some JSON data.
*
* @param {String} path The path of the json file.
* @returns The promise for the the JSON data as object.
...
...
@@ -29,6 +29,39 @@ var BROWSER_PASSWORD = "ignored";
return
new
RSVP
.
Promise
(
callback
);
});
}
/**
* Adds the method API from the method JSON data to the object.
*
* @param {object} object The container for the method.
* @param {object} method The method data from the protocol.
*/
function
addMethodAPI
(
object
,
method
)
{
var
callback
=
(
sender
,
params
)
=>
{
return
sender
(
`
${
object
.
domain
}
.
${
method
.
name
}
`
,
params
);
}
callback
[
"
description
"
]
=
method
.
description
;
callback
[
"
experimental
"
]
=
method
.
experimental
?
true
:
false
;
callback
[
"
type
"
]
=
"
method
"
;
object
[
method
.
name
]
=
callback
;
}
/**
* Adds the event API from the event JSON data to the object.
*
* @param {object} object The container for the event.
* @param {object} event The event data from the protocol.
*/
function
addEventAPI
(
object
,
event
)
{
// todo
}
/**
* Adds the type API from the type JSON data to the object.
*
* @param {object} object The container for the type.
* @param {object} type The type data from the protocol.
*/
function
addTypeAPI
(
object
,
type
)
{
// todo
}
/**
* Returns the devtools API for the given domain. Domains are defined
* by the devtools protocol, e.g. Page. Each domain defines multiple
...
...
@@ -37,30 +70,78 @@ var BROWSER_PASSWORD = "ignored";
* @param {object} domain The domain data from the devtools API.
* @returns The promise for the devtools API object and its name.
*/
function
getDevtoolsAPI
(
domain
)
{
function
getDevtoolsAPI
(
domain
)
{
var
callback
=
(
resolve
)
=>
{
console
.
log
(
domain
.
domain
);
resolve
({
name
:
domain
.
domain
,
object
:
null
});
var
object
=
{};
object
[
"
domain
"
]
=
domain
.
domain
;
object
[
"
description
"
]
=
domain
.
description
;
object
[
"
experimental
"
]
=
domain
.
experimental
?
true
:
false
;
(
domain
.
commands
||
[]).
forEach
((
method
)
=>
{
addMethodAPI
(
object
,
method
);
});
(
domain
.
events
||
[]).
forEach
((
event
)
=>
{
addEventAPI
(
object
,
event
);
});
(
domain
.
types
||
[]).
forEach
((
type
)
=>
{
addTypeAPI
(
object
,
type
);
});
resolve
([
domain
.
domain
,
object
]);
}
return
RSVP
.
Queue
().
push
(
function
()
{
return
new
RSVP
.
Promise
(
callback
);
});
}
/**
* Wraps the devtools API inside the gadget state which handels the
* connection with specific targets.
*
* @param {*} gadget
* @param {*} devtoolsAPI
*/
function
getWrappedDevtoolsAPI
(
gadget
,
devtoolsAPI
)
{
var
callback
=
(
resolve
)
=>
{
// handle connection over websocket
// wrap devtools function with sender
// special case for Browser/Target domain
resolve
(
devtoolsAPI
);
}
return
RSVP
.
Queue
().
push
(
function
()
{
return
new
RSVP
.
Promise
(
callback
);
});
}
var
gadget
=
rJS
(
window
);
gadget
.
declareService
(
function
()
{
rJS
(
window
)
.
setState
({
wsBrowser
:
null
,
wsTargets
:
[],
targetIndex
:
null
,
messages
:
{},
devtools
:
{},
})
.
declareService
(
function
()
{
var
gadget
=
this
;
return
getBrowserJSON
(
"
json/protocol
"
)
.
push
(
function
(
result
)
{
var
promises
=
[];
for
(
let
i
=
0
;
i
<
result
.
domains
.
length
;
i
++
)
{
promises
.
push
(
getDevtoolsAPI
(
result
.
domains
[
i
]));
}
var
promises
=
result
.
domains
.
map
(
getDevtoolsAPI
);
return
RSVP
.
all
(
promises
);
})
.
push
(
function
(
result
)
{
for
(
let
i
=
0
;
i
<
result
.
length
;
i
++
)
{
gadget
[
result
[
i
].
name
]
=
result
[
i
].
object
;
}
var
devtools
=
devtools
=
Object
.
fromEntries
(
result
);
return
getWrappedDevtoolsAPI
(
gadget
,
devtools
);
})
.
push
(
function
(
result
)
{
return
gadget
.
changeState
({
devtools
:
result
});
})
})
.
declareMethod
(
"
getDevtools
"
,
function
()
{
var
gadget
=
this
;
return
RSVP
.
Queue
().
push
(
function
()
{
return
gadget
.
state
.
devtools
;
})
})
.
onStateChange
(
function
(
ignored
)
{
var
gadget
=
this
;
console
.
log
(
gadget
.
state
.
devtools
);
})
}(
window
,
rJS
,
RSVP
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment