2

I have a content script loaded in Chrome. When I print a docx in google drive, Chrome opens the file in a new page which embeds the file as follows:

<embed width="100%" height="100%" name="plugin" id="plugin" src="https://doc-10-78-apps-viewer.googleusercontent.com/viewer/secure/pdf/ir7ttre15krrkcd49ssmvhgcd62pctgr/g7os4cqtfut2cmfmtp6cbjtg0h8mjvpo/1501677900000/drive/06250768728759024610/ACFrOgDlcxE7Uuy3abO4J9PRed248Bo9jg98MyEkYAWd__U3toMC_UmFuduTui1avT4riw0WkJ76SDJgVmnRCux35KP_KCojyy6Oude4B463MJeySVSryycvi6dd-38=" type="application/pdf" internalinstanceid="9" title="">

How can I read the file contents? I tried document.getElementById('plugin').contentDocument or document.getElementById('plugin').contentWindow but neither of them exists.

Yvonne Aburrow
  • 2,602
  • 1
  • 17
  • 47
elad-ep
  • 333
  • 1
  • 9
  • The print dialog is displayed outside of the tab context: if you inspect it you'll see it has `chrome://print` URL in devtools title. If you write a personal extension, not for the web store, you can try [adding chrome:// URL permissions](https://stackoverflow.com/questions/19042857/can-you-access-chrome-pages-from-an-extension). – wOxxOm Aug 02 '17 at 13:07
  • 3
    Anyway, `embed` element is handled by a plugin, which is a native code, so you can't access the contents. – wOxxOm Aug 02 '17 at 13:13
  • can I register to an event, so when the page is loaded and the file is fetched, my callback will be notified with the file contents? – elad-ep Aug 02 '17 at 17:38

0 Answers0