2

Using a Chrome extension, I'd like to:

  1. Detect if the current tab has loaded a PDF file.
  2. Add a button to the popup.html to offer to convert the PDF into HTML5.
  3. Get the URL of the PDF file and send that to an online service.

To accomplish #1, I think one of the solutions on this page could work: How can I detect the current tab's mime type in a Google Chrome extension?

The problem is that I'm having trouble getting the extension to run on the PDF page itself.

How do I run background.js of the extension on the PDF page?

My manifest file currently:

{
   "matches":[
      "https://*/*",
      "http://*/*"
   ],
   "run_at":"document_idle",
   "css":[
      "jquery-ui.css",
      "resizable.css"
   ],
   "js":[
      "jquery.js",
      "jquery-ui.js",
      "storage.js",
      "background.js"
   ],
   "all_frames":true
}
Community
  • 1
  • 1
  • You might want to [re]read the extension architecture article because the background page is an entirely different page (you can think of it as of a hidden browser tab that has its own DOM and scripts). By using such a misleading file name you're probably missing the simple solution which is to check the presence of `body > embed[name="plugin"][type="application/pdf"]` as you can see in the devtools inspector on a pdf page. – wOxxOm May 18 '17 at 03:47

1 Answers1

1

In the manifest file you should have this:

"content_scripts": [
 {
   "matches": ["*://*.pdf"],
   "js": ["background.js"]
 }
]
vatz88
  • 2,422
  • 2
  • 14
  • 25