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
ea89ea09
Commit
ea89ea09
authored
Jun 13, 2022
by
lukas.niegsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: fix misusage of cdp api
parent
4a7c3d19
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
10 deletions
+36
-10
chromium.js
chromium.js
+26
-10
connection.js
connection.js
+5
-0
index.html
index.html
+5
-0
No files found.
chromium.js
View file @
ea89ea09
...
...
@@ -5,6 +5,10 @@ class HeadlessChromium
this
.
websocket
=
websocket
}
// session websocket != page websocket
// page websocket can be found at localhost:<port>/json/version
// at webSocketDebuggerUrl where targetId = id
// question? how to make localhost GET request to get this resource ...
async
runCommand
(
command
,
params
=
{})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -19,17 +23,17 @@ class HeadlessChromium
server
.
close
()
var
data
=
JSON
.
parse
(
response
.
data
)
if
(
'
result
'
in
data
)
{
resolve
(
data
.
result
)
}
if
(
'
error
'
in
data
)
{
reject
(
data
.
error
)
}
reject
(
data
)
if
(
'
result
'
in
data
)
{
resolve
(
data
.
result
)
}
resolve
(
data
)
}
server
.
onerror
=
(
error
)
=>
{
...
...
@@ -59,21 +63,23 @@ class HeadlessChromium
return
await
this
.
runCommand
(
"
Page.enable
"
)
}
async
openNewPage
(
url
)
async
openNewPage
(
url
,
width
=
1920
,
height
=
1080
)
{
var
response
=
await
this
.
runCommand
(
"
Target.createTarget
"
,
{
url
:
url
})
var
response
=
await
this
.
runCommand
(
"
Target.createTarget
"
,
{
url
:
url
,
width
:
width
,
height
:
height
})
return
response
.
targetId
}
async
closePage
(
page
)
{
var
response
=
await
this
.
runCommand
(
"
Target.closeTarget
"
,
{
targetId
:
page
})
return
response
.
success
return
await
this
.
runCommand
(
"
Target.closeTarget
"
,
{
targetId
:
page
})
}
async
focusPage
(
page
)
{
await
this
.
runCommand
(
"
Target.activateTarget
"
,
{
targetId
:
page
})
var
response
=
await
this
.
runCommand
(
"
Target.attachToTarget
"
,
{
targetId
:
page
})
await
this
.
runCommand
(
response
.
method
,
response
.
params
)
console
.
log
(
response
)
}
async
printToPdf
()
...
...
@@ -81,4 +87,14 @@ class HeadlessChromium
var
response
=
await
this
.
runCommand
(
"
Page.printToPDF
"
)
return
response
}
async
canEmulate
()
{
return
await
this
.
runCommand
(
"
Emulation.canEmulate
"
)
}
async
getPages
()
{
return
await
this
.
runCommand
(
"
Target.getTargets
"
)
}
}
connection.js
View file @
ea89ea09
var
xmlHttp
=
new
XMLHttpRequest
();
xmlHttp
.
open
(
"
GET
"
,
"
http://localhost:9222/json/version
"
,
false
);
xmlHttp
.
send
(
null
);
console
.
log
(
xmlHttp
.
responseText
);
\ No newline at end of file
index.html
View file @
ea89ea09
...
...
@@ -14,8 +14,13 @@
async
function
html2pdf
(
url
)
{
var
pdf
=
await
browser
.
getPages
()
console
.
log
(
pdf
)
return
var
page
=
await
browser
.
openNewPage
(
url
)
await
browser
.
focusPage
(
page
)
await
browser
.
enablePage
()
var
pdf
=
browser
.
printToPdf
()
await
browser
.
closePage
(
page
)
return
pdf
...
...
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