Putting an iframe overlaid on a pdf document in a browser extension

I created a browser extension that lets you look up words in Wikipedia or Wiktionary without needing to open a new tab ( https://addons.mozilla.org/en-US/firefox/addon/in-page-lookup/ ). It is very useful when you are doing research and come across a word you don’t know or want to know more about. The only thing is, a lot of research content is in PDF format. A long time ago (~2013ish) I had an older version of the app based on the old add-on framework and that did let iframes show up over pdf documents but this has not been the case for many years. I don’t think the extension is even recognized in pdf documents, I get “Error: Could not establish connection. Receiving end does not exist” and there is no content script on the pdf page. So, my question is, is it possible to put an iframe over a pdf document? Do I need to work on the browser side, and if so, how? Thanks.

Sadly, extensions can’t run in PDF viewer since Firefox 60:

Since you cannot inject content scripts into the built-in PDF Viewer or other privileged pages, you might consider offering a context menu option. You can obtain the user’s selection when they use one of your context menu items even on a privileged page, and then you could present results in a popup (dropping down from the toolbar), floating window, or sidebar.

1 Like

Why is this marked “Resolved”? I’m not seeing any good solutions. I’m also not seeing a good security reason for putting pdfs in a separate, isolated module, given that websites could conceivably provide their own pdf viewer that has the same functionality.

Am I going to be able to inject a wikipedia.org iframe into a background script? That seems like a lot more of a security risk then just putting pdfs in the same module as html files.

No, when you open the popup (drop-down from toolbar button) you use a web URL in that popup, not in the background page. Best to only load pages you trust.