Chrome Extension ContextMenu for PDF

google-chrome, google-chrome-extension, javascript

Solution

I'm guessing that you want to add a context menu only when a PDF is shown in a tab, right? Just asking because I thought at first that you wanted to add the context menu on links to PDF files, which is indeed possible*. (as you probably know)

I couldn't find a way to do this directly, however one alternative could be to listen to `chrome.tabs.onActivated` and add or remove your context menu based on if the current URL matches a PDF file. One drawback is that it means asking for the `tabs` permission which might looks scary to users. ("This extension can access your tabs and browsing activity" or something like that)

*for the curious, you do it like this:

chrome.contextMenus.create({
    title: "Hello world",
    contexts: ["link"],
    targetUrlPatterns: ["*://*/*.pdf"]
});

(you would add the other options that interest you of course)

Problem

I'm developing a extension for the chrome browser and i want to add a specified contextmenu for pdf documents. I also add to specified contextmenus for the type "page" and "image". If i set the type to "all" then there is a contextmenu, but not specified for pdf documents. Is it possible to add a specified contextmenu for pdf documents or should i use a the type "all" an it make switch case in the clickEventHandler?! See more at: http://developer.chrome.com/extensions/contextMenus.html These are the "file" types: ``` contexts ( optional array of enum of "all", "page", "frame", "selection", "link", "editable", "image", "video", "audio", or "launcher" ) ```

Original source

Related problems