Open Bug 1988416 Opened 4 months ago Updated 4 months ago

user_pref('dom.allow_scripts_to_close_windows', true) doesn't work to close headless instance from with script

Categories

(Firefox :: Headless, defect)

Firefox 144
defect

Tracking

()

UNCONFIRMED

People

(Reporter: guest271314, Unassigned)

Details

Steps to reproduce:

Create profile specifcally for headless testing

$HOME/firefox/firefox-bin -CreateProfile wt

write some user preferences to the created profile

printf "user_pref('network.http.speculative-parallel-limit', 0);\n\
user_pref('devtools.console.stdout.content', true);\n\
user_pref('dom.allow_scripts_to_close_windows', true);" > "$HOME/.mozilla/firefox/$(ls $HOME/.mozilla/firefox | grep '\.wt')/user.js"

Launch headless instance, target Firefox headless, close headless instance when done using window.close() from within script

MOZ_HEADLESS_WIDTH=999 $HOME/firefox/firefox-bin -headless -P wt wt-client.html | grep WEBTRANSPORT_CLIENT

Inside of the script

<script type="module">
await (async () => {
  // ...
})()
()
.catch((e) => {
  console.log(`${WT_CLIENT}${e.message}`);
});
if (screen.width === 999) {
  globalThis.window.close();
}

Actual results:

Even when the if condition is removed, and close() is called directly after awaited async function, close() doesn't close the window and exit the headless Firefox instance launched on commad line.

Expected results:

Headless window closes, headless instance exits when close() is executed from within a script in headless mode.

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

When Firefox headless hangs, doesn't close when user_pref('dom.allow_scripts_to_close_windows', true); is set in user.js, then I have to do CTRL+C to exit I get these messages

^CExiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.
Exiting due to channel error.

which I suspect are prompts sent by the browser for something that the user can't confirm or deny because there's no GUI.

So I think I need the exact preferences to be set to disable first-run, default-browser, whatever prompts the browser is trying to send to the user.

Apparently user_pref('dom.allow_scripts_to_close_windows', true); alone is not sufficient to close the headless browser from scripts.

Severity: -- → S3
Component: DOM: Core & HTML → Headless
Priority: -- → P3
Product: Core → Firefox
Severity: S3 → --
Priority: P3 → --
You need to log in before you can comment on or make changes to this bug.