1

I'm using chrome version 109.0.5414.75 and developping an extension. And when I call print() method to save a page as pdf file, I can't catch afterprint event. But when I type Ctrl+P commnad then the event fired and after this, print() method fire afterprint event normaly.

The code is in content.js of developping extension.

The code is very simple in content.js

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

When I save as pdf by print() from console of developer tool, the event not fired. but by Ctrl+P if fired.

This situation happens an environment but on other systems no problem(fire the event). Does someone have some ideas to solve this?

I can use eventdispatch to deal with it, but I want the timing that saved pdf(afterpring).

Koji
  • 11
  • 2
  • Dou you mean "user save as pdf" as Ctrl+P and save as pdf ? I tried and got feedback(afterprint). But print() was not. – Koji Jan 14 '23 at 03:32
  • The code is very simple in content.js `window.addEventListener('afterprint', (event) => {console.log('After printing'); });` When I save as pdf by print() from console of developer tool, the event not fired. but by Ctrl+P if fired. – Koji Jan 14 '23 at 04:42
  • I found a solution from https://stackoverflow.com/questions/18325025/how-to-detect-window-print-finish. Using window.matchMedia works. But I don't know why afterprint event does not works on my env. – Koji Jan 14 '23 at 19:46
  • I'm using chrome version 109.0.5414.87 and have the same problem as you. Then I download Chrome Canary with version 112.0.5569.2, and it works. So I think maybe it's the issue of Chrome? – Nina Jan 31 '23 at 06:41

0 Answers0