New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 834409 link

Starred by 3 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: ----


Participants' hotlists:
Hotlist-1

Previous locations:
chromedriver:1890


Sign in to add a comment

Headless chrome window.print()

Reported by uwiz...@gmail.com, Jul 20 2017

Issue description

Imagine js page with window.print() js code.
If you try to open such page with headless chome, there is no way to accept or close the dialog caused py print() function.
Calling .close() on chrome-remote-interface also does nothing
 
Labels: Needs-Feedback
Could you please provide a repro test along with the page under testing? Thanks.

Comment 2 Deleted

Comment 3 by uwiz...@gmail.com, Jul 25 2017

The page with window.print(): 
http://www.galant-biz.ru/print.html


node.js code:
(async function() {
	
	const Koa = require('koa');
	const chrome = require('chrome-remote-interface');
	
	const app = new Koa();
	app.listen('9223');
	
	const target = await chrome.New();
	const client = await chrome({ target: target.id });
	const { DOM, Network, Page, Runtime } = client;
	await Promise.all([Page.enable(), Runtime.enable(), DOM.enable(), Network.enable()]);
	await Page.navigate({ url: 'http://www.galant-biz.ru/print.html' });
	setTimeout(async () => {
		console.log('timeout')
		await client.close();
		console.log('client closed')
		await chrome.Close(target);
	},10000)
	await Page.loadEventFired();
})();


Function loadEventFired() is never fired, client.close() is never finished.

Cc: johnchen@chromium.org jzfeng@chromium.org
It seems chrome://print dialog doesn't get open in HeadlessChrome.

You can check by calling GetWindowHandles() after navigating to 'http://www.galant-biz.ru/print.html' .

1) In normal Chrome, here is the output:

[24.948][INFO]: COMMAND GetWindows {
}
[24.948][DEBUG]: DevTools request: http://localhost:12506/json
[24.948][DEBUG]: DevTools response: [ {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:12506/devtools/page/65a1c866-629b-4085-9cc1-755c359dce29",
   "id": "65a1c866-629b-4085-9cc1-755c359dce29",
   "title": "Координаты «БЦ ГАЛАНТ» — версия для печати",
   "type": "other",
   "url": "chrome://print/",
   "webSocketDebuggerUrl": "ws://localhost:12506/devtools/page/65a1c866-629b-4085-9cc1-755c359dce29"
}, {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:12506/devtools/page/1b9150e9-e965-46df-b0f2-5c5d108d15a1",
   "id": "1b9150e9-e965-46df-b0f2-5c5d108d15a1",
   "title": "Chrome Automation Extension",
   "type": "background_page",
   "url": "chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html",
   "webSocketDebuggerUrl": "ws://localhost:12506/devtools/page/1b9150e9-e965-46df-b0f2-5c5d108d15a1"
}, {
   "description": "",
   "id": "27f91d65-1118-47db-8431-451200a642ed",
   "title": "Координаты «БЦ ГАЛАНТ» — версия для печати",
   "type": "page",
   "url": "http://www.galant-biz.ru/print.html"
} ]
[24.948][INFO]: RESPONSE GetWindows [ "CDwindow-27f91d65-1118-47db-8431-451200a642ed", "CDwindow-65a1c866-629b-4085-9cc1-755c359dce29" ]



2) whereas, in Headless Chrome, the output is as follows:

[13.102][INFO]: COMMAND GetWindows {
}
[13.102][DEBUG]: DevTools request: http://127.0.0.1:9222/json
[13.102][DEBUG]: DevTools response: [ {
   "description": "",
   "id": "83577781-f7ad-4694-9006-03d31f141099",
   "title": "Координаты «БЦ ГАЛАНТ» — версия для печати",
   "type": "page",
   "url": "http://www.galant-biz.ru/print.html"
} ]

[13.102][INFO]: RESPONSE GetWindows [ "CDwindow-83577781-f7ad-4694-9006-03d31f141099" ]

Notice that "chrome://print/" is missing in output of HeadlessChrome.

Jianzhou: Is "chrome://print/" not supported on HeadlessChrome?

Comment 5 by jzfeng@chromium.org, Jul 29 2017

"chrome://print/" is not supported in headless chrome. The window.print() wouldn't open the printing dialog and the command is just ignored.
In headless chrome, the print settings are set via Page.printToPDF devtools command, instead of the printing dialog, which is a UI.

Maybe we can add the print to pdf feature into chromedriver so that users can print the page?

Comment 6 by jzfeng@chromium.org, Jul 29 2017

Oh, I just notice you are using chrome-remote-interface instead of chromedriver. So you can just use the Page.printToPDF command to print the page.

Comment 7 by jzfeng@chromium.org, Jul 29 2017

I will take a look at why loadEventFired is never fired.
Labels: HeadlessChrome

Comment 9 by uwiz...@gmail.com, Aug 14 2017

Any update? 
The main question is actually why loadEventFired is never fired. I do not need to print this page, just want to ignore window.print() somehow. But it seems to hang the loadEventFired.

Comment 10 by uwiz...@gmail.com, Aug 31 2017

Anybody is working on this?
jzfeng@: Could you please provide an update to this issue? Thanks!
Owner: jzfeng@chromium.org
Status: Assigned (was: Unconfirmed)

Comment 13 by a...@view26.com, Apr 18 2018

Any updates on Chrome Headless Driver's ability to support printToPDF via API ? 
Owner: eseckler@chromium.org
Hi Eric, I think Jianzhou is no longer working on headless Chrome. Could you please take a look at this bug? Thanks.
Labels: -Needs-Feedback -HeadlessChrome
Owner: caseq@chromium.org
Summary: Headless: No loadEventFired when window.print() called in page. (was: Headless chrome window.print())
Off to caseq@. Might also be a good starter bug for Johannes?

Sounds like the problem here is that the load event is not fired. Printing works as expected.
Project: chromium
Moved issue chromedriver:1890 to now be issue chromium:834409.
Components: Internals>Headless
Cc: johannes@chromium.org
Owner: caseq@chromium.org
Labels: Pri-2
Setting defect without priority to Pri-2.

Sign in to add a comment