【问题标题】:Chrome extension, chrome extension communicationChrome扩展,chrome扩展通讯
【发布时间】:2015-01-06 05:32:55
【问题描述】:

下面是我的 manifest.json:
{

 "name": "My Extension Name",

 "version": "1.9.1",

 "manifest_version": 2,

 "icons": {  "16": "icon16.png",

             "48": "icon48.png",

             "128": "icon128.png" },

 "homepage_url": "https://www.mysite.com",

 "description": "My Extension Description",

 "permissions": ["http://www.example.com/*"],

 "content_scripts" : [{

         "matches" : [ "http://www.example.com/*"],

         "js" : ["contentscript.js"],

         "run_at" : "document_end"

  }],

        "web_accessible_resources": ["script.js"]

}

我的 contentscript.js 是:

var s = document.createElement('script');

s.src = chrome.extension.getURL("script.js");

(document.head||document.documentElement).appendChild(s);

script.js:

$.post("https://www.mysite.com/app/myfolder/", 函数(html){

  $("body").prepend(html);

});

我想访问http://www.example.com/ 中的DOM。 http://www.example.com/ 中有一个表格。单击表单的提交按钮时,我想获取 www.mysite.com 中的帖子值。如何做到这一点?

【问题讨论】:

    标签: google-chrome google-chrome-extension


    【解决方案1】:

    是的,您可以使用chrome.webRequest 接口拦截、处理和篡改站点的POST 数据。只需在您的 manifest.json 中实现 webRequest 并在您的内容脚本中添加一个 onBeforeSendHeaders 函数。更多文档可以在Google Chrome Extension Developers Documentation 上找到。

    【讨论】:

    • 内容脚本只能访问limited number of Chrome extension APIschrome.webRequest 不是内容脚本可以访问的。与chrome.webRequest 相关的任何事情都必须在后台脚本中完成。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    相关资源
    最近更新 更多