Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it work with Chrome pdf plugin #8

Open
bersbersbers opened this issue Sep 10, 2015 · 2 comments
Open

Make it work with Chrome pdf plugin #8

bersbersbers opened this issue Sep 10, 2015 · 2 comments

Comments

@bersbersbers
Copy link

I would love to use this extension to free some pdf from iframes, such as this one:
http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6919256

However, this is a bit tricky. I have tried to work on this, with the following results.

The context menu can be enabled for the Chrome pdf plugin using
contexts: ['all']
instead of
contexts: ['frame'].

Then, one can use
var url = clickData.srcUrl || clickData.frameUrl || clickData.pageUrl;
to obtain the url to the pdf file in the onClicked listener.

However, tab.id == -1. This is where I am stuck. Are plugin extensions living in some invalid tab rather than the real one? Is this a Chromium bug? Can one maybe use the currently active tab instead?

@bersbersbers
Copy link
Author

Alright, I fixed this. So in addition to the above changes to the contexts (from 'frame' to 'all'), this solves my problem:

chrome.contextMenus.onClicked.addListener(function(clickData, tab) {
var handler = COMMANDS[clickData.menuItemId].handler;
if (tab.id == -1) {
// for example, when in pdf plugin
var url = clickData.srcUrl;
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
handler(url, tabs[0]);
});
} else {
var url = clickData.frameUrl || clickData.pageUrl;
handler(url, tab);
}
});

There may be some more testing required, but I like it so far.

@dportabella
Copy link

did you find out the real problem?
i have the same issue when i have a pdf file:
when clicking on my context menu (chrome.contextMenus.onClicked), I get tab.id == -1.
however, if i click on my browserAction icon (chrome.browserAction.onClicked), I get the valid tab.id.
any idea of why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants