Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pagedjs-cli
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mathis Poncet
pagedjs-cli
Commits
501b2ce3
Commit
501b2ce3
authored
2 years ago
by
Mathis Poncet
Browse files
Options
Downloads
Patches
Plain Diff
fix(#369)-feat: infinite loop cause by requestInterception and load file as buffer
parent
df24df75
No related branches found
No related tags found
No related merge requests found
Pipeline
#32761
failed with stages
in 43 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/printer.js
+4
-69
4 additions, 69 deletions
src/printer.js
with
4 additions
and
69 deletions
src/printer.js
+
4
−
69
View file @
501b2ce3
...
...
@@ -58,7 +58,7 @@ class Printer extends EventEmitter {
return
this
.
browser
;
}
async
render
(
input
)
{
async
render
(
html
)
{
let
resolver
;
let
rendered
=
new
Promise
(
function
(
resolve
,
reject
)
{
resolver
=
resolve
;
...
...
@@ -77,72 +77,7 @@ class Printer extends EventEmitter {
page
.
_client
.
send
(
'
Emulation.setDefaultBackgroundColorOverride
'
,
{
color
:
this
.
overrideDefaultBackgroundColor
});
}
let
uri
,
url
,
relativePath
,
html
;
if
(
typeof
input
===
"
string
"
)
{
try
{
uri
=
new
URL
(
input
);
url
=
input
;
}
catch
(
error
)
{
relativePath
=
path
.
resolve
(
dir
,
input
);
if
(
this
.
browserWSEndpoint
)
{
html
=
fs
.
readFileSync
(
relativePath
,
'
utf-8
'
)
}
else
{
url
=
"
file://
"
+
relativePath
;
}
}
}
else
{
url
=
input
.
url
;
html
=
input
.
html
;
}
await
page
.
setRequestInterception
(
true
);
page
.
on
(
'
request
'
,
(
request
)
=>
{
let
uri
=
new
URL
(
request
.
url
());
let
{
host
,
protocol
,
pathname
}
=
uri
;
let
local
=
protocol
===
"
file:
"
if
(
local
&&
this
.
withinAllowedPath
(
pathname
)
===
false
)
{
request
.
abort
();
return
;
}
if
(
local
&&
!
this
.
allowLocal
)
{
request
.
abort
();
return
;
}
if
(
host
&&
this
.
isAllowedDomain
(
host
)
===
false
)
{
request
.
abort
();
return
;
}
if
(
host
&&
!
this
.
allowRemote
)
{
request
.
abort
();
return
;
}
request
.
continue
();
});
if
(
html
)
{
await
page
.
setContent
(
html
);
if
(
url
)
{
await
page
.
evaluate
((
url
)
=>
{
let
base
=
document
.
querySelector
(
"
base
"
);
if
(
!
base
)
{
base
=
document
.
createElement
(
"
base
"
);
document
.
querySelector
(
"
head
"
).
appendChild
(
base
);
}
base
.
setAttribute
(
"
href
"
,
url
);
},
url
);
}
}
else
{
await
page
.
goto
(
url
);
}
await
page
.
setContent
(
html
,
{
waitUntil
:
"
networkidle0
"
});
await
page
.
evaluate
(()
=>
{
window
.
PagedConfig
=
window
.
PagedConfig
||
{};
...
...
@@ -154,7 +89,6 @@ class Printer extends EventEmitter {
await
page
.
addScriptTag
({
path
:
scriptPath
});
for
(
const
script
of
this
.
additionalScripts
)
{
await
page
.
addScriptTag
({
path
:
script
...
...
@@ -290,7 +224,8 @@ class Printer extends EventEmitter {
}
async
pdf
(
input
,
options
=
{})
{
let
page
=
await
this
.
render
(
input
)
let
bufferInput
=
fs
.
readFileSync
(
input
,
"
utf8
"
);
let
page
=
await
this
.
render
(
bufferInput
,
options
)
.
catch
((
e
)
=>
{
throw
e
;
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment