Chrome扩展程序,Chrome扩展程序通信 [英] Chrome extension, chrome extension communication
问题描述
以下是我的manifest.json:
{
name:My Extension Name ,
版本:1.9.1,
manifest_version:2,
图标:{16 :icon16.png,
48:icon48.png,
128:icon128.png},
homepage_url:https://www.mysite.com,
description:我的扩展说明,
permissions:[ http://www.example.com/*],
content_scripts:[{
matches:[http://www.example。
js:[contentscript.js],
run_at:document_end
} ],
web_accessible_resources:[script.js]
}
我的contentscript.js是:
var s = document.createElement('script'); / p>
= src = chrome.extension.getURL(script.js);
(document.head || document.documentEleme nt).appendChild(s);
script.js:
$。post( https://www.mysite.com/app/myfolder/ ,function(html){
$(body)。prepend(html);
});
通过 http://www.example.com/ 访问DOM。 http://www.example.com/ 中有一个表单。当点击表单的提交按钮时,我想要在www.mysite.com中获取帖子值。如何实现这一点?
是的,您可以拦截,处理和篡改网站的 POST
使用 chrome.webRequest
界面的数据。只需在 manifest.json
中实现 webRequest
并添加一个 onBeforeSendHeaders
功能在你的内容脚本中。更多文档可以在 Google Chrome扩展开发者文档中找到。
Below is my 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"]
}
My contentscript.js is:
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/", function(html){
$("body").prepend(html);
});
I would like to access the DOM in http://www.example.com/. There is a form in http://www.example.com/. when the submit button of the form is clicked, iw ould like to get the post values in www.mysite.com. How to achieve this?
Yes, you can intercept, process, and tamper with a site's POST
data using the chrome.webRequest
interface. Just implement webRequest
in your manifest.json
and add an onBeforeSendHeaders
function in your content-script. More documentation can be found on the Google Chrome Extension Developers Documentation.
这篇关于Chrome扩展程序,Chrome扩展程序通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!