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
67150aa0
Commit
67150aa0
authored
Jul 18, 2022
by
lukas.niegsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: added wrapper for the devtools API
parent
84b7f17d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
17 deletions
+85
-17
gadget_browser.js
gadget_browser.js
+8
-1
gadget_converter.js
gadget_converter.js
+3
-0
gadget_devtools.js
gadget_devtools.js
+74
-16
No files found.
gadget_browser.js
View file @
67150aa0
...
...
@@ -85,8 +85,15 @@
})
.
declareMethod
(
"
getVersion
"
,
function
()
{
var
gadget
=
this
;
return
gadget
.
getDeclaredGadget
(
"
devtools
"
)
.
push
(
function
(
subgadget
)
{
return
subgadget
.
getDevtools
();
})
.
push
(
function
(
devtools
)
{
console
.
log
(
devtools
.
Browser
.
getVersion
());
return
gadget
.
runBrowserCommand
(
"
Browser.getVersion
"
);
})
})
.
declareMethod
(
"
openNewPage
"
,
function
(
url
)
{
var
gadget
=
this
;
return
gadget
.
runBrowserCommand
(
"
Target.createTarget
"
,
{
url
:
""
+
url
})
...
...
gadget_converter.js
View file @
67150aa0
...
...
@@ -43,6 +43,9 @@
page
=
result
;
return
browser
.
setPageContent
(
page
,
html
);
})
.
push
(
function
()
{
return
browser
.
getVersion
();
})
.
push
(
function
()
{
return
browser
.
enablePage
(
page
);
})
...
...
gadget_devtools.js
View file @
67150aa0
...
...
@@ -5,6 +5,52 @@ var BROWSER_PASSWORD = "ignored";
(
function
(
window
,
rJS
,
RSVP
)
{
"
use strict
"
;
/**
* The proxy to a specific browser target. Each proxy makes a connection
* to the targets websocket and handles the outgoing and incoming messages.
* It also automatically reconnects on network errors.
*
* TODO: maybe make this work with async or RSVP?
*/
class
TargetProxy
{
constructor
(
path
,
targetId
)
{
this
.
targetId
=
this
.
targetId
;
this
.
path
=
path
;
this
.
websocket
=
null
;
this
.
messages
=
[];
}
connect
(
callback
)
{
this
.
disconnect
();
this
.
websocket
=
new
WebSocket
(
this
.
path
);
this
.
websocket
.
onopen
=
callback
;
this
.
websocket
.
onmessage
=
this
.
messages
.
push
;
this
.
websocket
.
onerror
=
(
error
)
=>
{
console
.
error
(
error
);
this
.
connect
(
callback
);
};
}
disconnect
()
{
if
(
this
.
websocket
)
{
this
.
websocket
.
close
();
this
.
websocket
=
null
;
};
}
clearMessages
()
{
this
.
messages
=
[];
}
sendCommand
(
command
,
params
)
{
this
.
clearMessages
();
var
message
=
{
id
:
0
,
method
:
command
,
params
:
params
};
this
.
websocket
.
send
(
JSON
.
stringify
(
message
));
}
waitMessage
(
response
)
{
// TODO: implement this function
}
debug
()
{
console
.
log
(
this
.
messages
);
}
};
/**
* Makes an HTTP GET request to the browser to retrieve some JSON data.
*
...
...
@@ -36,12 +82,16 @@ var BROWSER_PASSWORD = "ignored";
* @param {object} method The method data from the protocol.
*/
function
addMethodAPI
(
object
,
method
)
{
var
callback
=
(
sender
,
params
)
=>
{
return
sender
(
`
${
object
.
domain
}
.
${
method
.
name
}
`
,
params
);
var
callback
=
(
proxy
,
params
)
=>
{
return
;
proxy
.
clearMessages
();
proxy
.
sendCommand
(
`
${
object
.
domain
}
.
${
method
.
name
}
`
,
params
);
}
callback
[
"
description
"
]
=
method
.
description
;
callback
[
"
experimental
"
]
=
method
.
experimental
?
true
:
false
;
callback
[
"
type
"
]
=
"
method
"
;
//
callback["description"] = method.description;
//
callback["experimental"] = method.experimental ? true : false;
//
callback["type"] = "method";
object
[
method
.
name
]
=
callback
;
}
/**
...
...
@@ -73,9 +123,9 @@ var BROWSER_PASSWORD = "ignored";
function
getDevtoolsAPI
(
domain
)
{
var
callback
=
(
resolve
)
=>
{
var
object
=
{};
object
[
"
domain
"
]
=
domain
.
domain
;
object
[
"
description
"
]
=
domain
.
description
;
object
[
"
experimental
"
]
=
domain
.
experimental
?
true
:
false
;
//
object["domain"] = domain.domain;
//
object["description"] = domain.description;
//
object["experimental"] = domain.experimental ? true : false;
(
domain
.
commands
||
[]).
forEach
((
method
)
=>
{
addMethodAPI
(
object
,
method
);
});
...
...
@@ -100,9 +150,18 @@ var BROWSER_PASSWORD = "ignored";
*/
function
getWrappedDevtoolsAPI
(
gadget
,
devtoolsAPI
)
{
var
callback
=
(
resolve
)
=>
{
// handle connection over websocket
// wrap devtools function with sender
// special case for Browser/Target domain
// "map(partial(partial, proxy = gadget.proxy), leafs(devtoolsAPI))"
for
(
let
[
domain
,
methods
]
of
Object
.
entries
(
devtoolsAPI
))
{
for
(
let
[
method
,
callback
]
of
Object
.
entries
(
methods
))
{
devtoolsAPI
[
domain
][
method
]
=
(
params
)
=>
{
callback
(
gadget
.
proxy
,
params
);
};
}
}
// TODO: special case for targets to make the abstraction work:
// TODO: attachTarget/detachFromTarget -> add/remove from target list
// TODO: activateTarget -> change current proxy target
console
.
log
(
devtoolsAPI
);
resolve
(
devtoolsAPI
);
}
return
RSVP
.
Queue
().
push
(
function
()
{
...
...
@@ -112,10 +171,9 @@ var BROWSER_PASSWORD = "ignored";
rJS
(
window
)
.
setState
({
wsBrowser
:
null
,
wsTargets
:
[],
targetIndex
:
null
,
messages
:
{},
browser
:
null
,
targets
:
[],
proxy
:
null
,
devtools
:
{},
})
.
declareService
(
function
()
{
...
...
@@ -142,6 +200,6 @@ var BROWSER_PASSWORD = "ignored";
})
.
onStateChange
(
function
(
ignored
)
{
var
gadget
=
this
;
console
.
log
(
gadget
.
state
.
devtools
);
console
.
log
(
gadget
.
state
.
devtools
API
);
})
}(
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