Internet Download Manager Chrome扩展程序如何运作?

时间:2013-07-12 06:12:54

标签: javascript google-chrome google-chrome-extension

我看到IDM创建了chrome扩展来从浏览器中捕获文件。 我打开它,这是在扩展名

上编写的如此短的代码 backhground.html中的

<html>
<body>
<embed id="__IDM__" type="application/x-idm-downloader" width="0" height="0"/>
<script src="background.js"></script>
</body>
</html>

并在background.js

var plugin = document.getElementById('__IDM__');
if (plugin)
{
    plugin.Initialize();

    chrome.webRequest.onBeforeRequest.addListener(plugin.onBeforeRequest, { urls: ['<all_urls>'], types: ['main_frame','sub_frame','object','image'] }, ['blocking']);
    chrome.webRequest.onHeadersReceived.addListener(plugin.onHeadersReceived, { urls: ['<all_urls>'], types: ['image'] }, ['responseHeaders']);
}

function injectContentScript(tabs)
{
    var details = { file: 'contentscript.js', allFrames: true };

    for (var i = 0; i < tabs.length; i++)
        try { chrome.tabs.executeScript(tabs[i].id, details); }
    catch (exc) { }
}

chrome.tabs.query({ url: 'http://*/*'  }, injectContentScript);
chrome.tabs.query({ url: 'https://*/*' }, injectContentScript);

将所有网址发送到嵌入文件! 我不明白这个嵌入工作是怎么做的,我怎样才能创建这样的嵌入代码来从浏览器中捕获数据以了解它是如何工作的

我记得yahoo messenger有一些像代码一样的东西,当用户点击浏览器雅虎聊天框打开,这个代码在win注册表创建。我想这会是那样但是如何!?

0 个答案:

没有答案