Alex Rivera | Logout

Chrome extension content scripts and iframe

Asked 2011-07-04T10:41:11.840
25

I'm tryng to make an extension for google chrome that does this things:

Run when loading www.example.com example.com has an iframe to another site, i need to get access to a link from this iframe (this is rapidshare, I need to grab the downloadlink)

So far so good, but..

Then I need the extension to inform the link url to example.com for further processing.

Any ideas o directions??

I've read http://code.google.com/chrome/extensions/content_scripts.html#host-page-communication but can't make it work...

Edit
Report

1 Answer

58

You need to inject 2 content scripts:

"content_scripts": [
    {
      "matches": ["http://www.example.com/*"],
      "js": ["example.js"]
    },{
      "matches": ["http://www.rapidshare.com/*"],
      "all_frames": true,
      "js": ["rapidshare.js"]
    }
]

In order to transfer the link from one script to another you need to communicate through background page:

rapidshare.js:

chrome.runtime.sendMessage({url: "link"});

background.js:

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    chrome.tabs.sendMessage(sender.tab.id, request);
    sendResponse({});
});

example.js:

chrome.runtime.onRequest.addListener(function(request, sender, sendResponse) {
    console.log("received url:", request.url);
    sendResponse({});
});
answered 2011-07-04T15:18:56.663

Your Answer