How to capture afterprint event from a PDF page?

Skip to first unread message

Hotzlock GM

Sep 29, 2022, 1:15:23 PMSep 29
to Chromium Extensions
Why don't the

window.addEventListener('afterprint', (event) => { console.log('After print'); }); window.onafterprint = (event) => { console.log('After print'); };

commands work on PDF pages? I made a code to send a message to my background.js after print, the code works perfectly on all chrome pages, but on PDF pages they just don't work, and they don't return any kind of error?

 ["tabs", "activeTab", "nativeMessaging", "scripting"], 
 "host_permissions": [ "http://*/*", "https://*/*" ], 
 "content_scripts":[ { "js": ["popup.js"], "matches": ["<all_urls>"] }

Other commands like Window.Print() and functions work perfectly... but the others that I mentioned above don't work, they don't return an error, simply nothing happens on these PDF pages

Stefan Van Damme

Oct 2, 2022, 4:41:12 PMOct 2
to Chromium Extensions, Hotzlock GM
Hi there,

"permissions":  ["tabs", "activeTab", "nativeMessaging", "scripting"], 
I see you use permission "tabs" and "activeTab". It is best to use one of the permissions and not both.

The "tabs" permission
This permission does not give access to the chrome.tabs namespace. Instead, it grants an extension the ability to call tabs.query() against four sensitive properties on tabs.Tab instances: urlpendingUrltitle, and favIconUrl.
Host permissions
Host permissions allow an extension to read and query a matching tab's four sensitive tabs.Tab properties. They can also interact directly with the matching tabs using methods such as tabs.captureVisibleTab()tabs.executeScript()tabs.insertCSS(), and tabs.removeCSS().
The "activeTab" permission
activeTab grants an extension temporary host permission for the current tab in response to a user invocation. Unlike host permissions, activeTab does not trigger any warnings.


Oct 2, 2022, 5:54:08 PMOct 2
to Chromium Extensions,, Hotzlock GM
It's just a bug in Chrome. The event should fire when you close the Print dialog, but it doesn't.
PDF pages sometimes behave differently in Chrome because of the way the PDF viewer is implemented.
I don't think there's anything you can do, other than to report the bug.

Reply all
Reply to author
0 new messages