Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
news-harvester
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Back End
news-harvester
Commits
6d415fe0
Commit
6d415fe0
authored
Jul 31, 2026
by
谢宇轩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: ensure chromium error
parent
c8b8bc46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
10 deletions
+42
-10
config-template.json
references/config-template.json
+0
-8
ensure-chromium.js
scripts/ensure-chromium.js
+42
-2
No files found.
references/config-template.json
View file @
6d415fe0
...
...
@@ -16,14 +16,6 @@
"articleUrlPattern"
:
"theconversation
\\
.com/[
\\
w-]+-
\\
d+$"
,
"vaultFolder"
:
"The Conversation"
,
"enabled"
:
true
},
{
"id"
:
"reuters-world"
,
"name"
:
"路透社 World"
,
"homepageUrl"
:
"https://www.reuters.com/world/"
,
"method"
:
"browser"
,
"vaultFolder"
:
"路透社 World"
,
"enabled"
:
true
}
]
}
scripts/ensure-chromium.js
View file @
6d415fe0
...
...
@@ -189,6 +189,11 @@ function spawnBrowser(bin, opts) {
'--no-default-browser-check'
,
'--disable-extensions'
,
'--disable-gpu'
,
// Let Chromium auto-detect Wayland vs X11 on Linux. Without this it
// defaults to the X11 backend and crashes with "Missing X server or
// $DISPLAY" on Wayland-only sessions (common on Arch/GNOME/Sway). Harmless
// on macOS/Windows — they don't use the Ozone backend.
'--ozone-platform-hint=auto'
,
];
// --no-sandbox is only needed when running as root (typical in Linux/Docker
// containers, where Chromium refuses to start with the sandbox as root). On
...
...
@@ -206,6 +211,7 @@ function spawnBrowser(bin, opts) {
detached
:
true
,
stdio
:
[
'ignore'
,
'ignore'
,
logFd
],
windowsHide
,
env
:
{
...
process
.
env
},
});
child
.
on
(
'error'
,
(
e
)
=>
{
console
.
error
(
`Chromium spawn error:
${
e
.
message
}
`
);
...
...
@@ -222,6 +228,34 @@ function tailFile(filePath, lines = 25) {
}
catch
(
e
)
{
return
'(no log file)'
;
}
}
// Diagnose display/X11 failures — common on Wayland-only Linux sessions where
// $DISPLAY is unset and Chromium wasn't told (or couldn't) use the Wayland
// backend. Returns a multi-line hint string.
function
displayDiagnostic
()
{
const
d
=
process
.
env
.
DISPLAY
?
`set (
${
process
.
env
.
DISPLAY
}
)`
:
'unset'
;
const
w
=
process
.
env
.
WAYLAND_DISPLAY
?
`set (
${
process
.
env
.
WAYLAND_DISPLAY
}
)`
:
'unset'
;
const
lines
=
[
` $DISPLAY:
${
d
}
`
,
` $WAYLAND_DISPLAY:
${
w
}
`
,
];
if
(
!
process
.
env
.
DISPLAY
&&
!
process
.
env
.
WAYLAND_DISPLAY
)
{
lines
.
push
(
' ⚠️ Neither is set — this shell is not attached to a graphical session.'
);
lines
.
push
(
' Run --login from a terminal inside your desktop (GUI terminal), or'
);
lines
.
push
(
' export the variables from a graphical session, e.g.:'
);
lines
.
push
(
' export WAYLAND_DISPLAY=wayland-0 # Wayland'
);
lines
.
push
(
' export DISPLAY=:0 # X11 / XWayland'
);
}
else
if
(
!
process
.
env
.
DISPLAY
&&
process
.
env
.
WAYLAND_DISPLAY
)
{
lines
.
push
(
' (Wayland session. --ozone-platform-hint=auto is already passed; if it still'
);
lines
.
push
(
' fails, force Wayland by adding --ozone-platform=wayland to the browser args,'
);
lines
.
push
(
' or run in a GUI terminal that also exports $DISPLAY for XWayland.)'
);
}
return
lines
.
join
(
'
\
n'
);
}
function
looksLikeDisplayFailure
(
log
)
{
return
/Missing X server|
\$
DISPLAY|platform failed to initialize|ozone/i
.
test
(
log
);
}
// ── Main ────────────────────────────────────────────────────────────────────
async
function
ensureChromium
(
config
,
portOverride
)
{
...
...
@@ -248,12 +282,14 @@ async function ensureChromium(config, portOverride) {
const
v
=
await
waitForCdp
(
opts
.
cdpPort
,
30000
,
500
);
return
{
port
:
opts
.
cdpPort
,
pid
,
browser
:
v
.
Browser
,
bin
,
logPath
};
}
catch
(
e
)
{
const
logTail
=
tailFile
(
logPath
);
const
hint
=
looksLikeDisplayFailure
(
logTail
)
?
'
\
n'
+
displayDiagnostic
()
+
'
\
n'
:
''
;
throw
new
Error
(
`Chromium did not become ready on port
${
opts
.
cdpPort
}
.\n`
+
` binary:
${
bin
}
\n`
+
` userData:
${
opts
.
userDataDir
}
\n`
+
` log:
${
logPath
}
\n`
+
` stderr tail:\n
${
tailFile
(
logPath
)
}
`
` stderr tail:\n
${
logTail
}${
hint
}
`
);
}
}
...
...
@@ -407,11 +443,15 @@ async function cmdLogin(config, flagUrl, flagPort, flagProfile) {
console
.
log
(
` profile:
${
profile
}
`
);
console
.
log
(
` log:
${
logPath
}
`
);
}
catch
(
e
)
{
const
logTail
=
tailFile
(
logPath
);
console
.
error
(
`❌ Browser did not become ready on :
${
port
}
within 15s.`
);
console
.
error
(
` binary:
${
bin
}
`
);
console
.
error
(
` profile:
${
profile
}
`
);
console
.
error
(
` log:
${
logPath
}
`
);
console
.
error
(
` stderr tail:\n
${
tailFile
(
logPath
)}
`
);
console
.
error
(
` stderr tail:\n
${
logTail
}
`
);
if
(
looksLikeDisplayFailure
(
logTail
))
{
console
.
error
(
`\n
${
displayDiagnostic
()}
`
);
}
process
.
exit
(
1
);
}
...
...
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