以下是我的manifest.json: {
name:My Extension Name , 版本:1.9.1, manifest_version:2, 图标:{16 :icon16.png, 48:icon48.png, 128:icon128.png}, homepage_url:www.mysite, description:我的扩展说明, permissions:[ www.example/*], 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( www.mysite/app/myfolder/ ,function(html){
$(body)。prepend(html);
});
通过 www.example/ 访问DOM。 www.example/ 中有一个表单。当点击表单的提交按钮时,我想要在www.mysite中获取帖子值。如何实现这一点?
解决方案是的,您可以拦截,处理和篡改网站的 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": "www.mysite", "description": "My Extension Description", "permissions": ["www.example/*"], "content_scripts" : [{ "matches" : [ "www.example/*"], "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("www.mysite/app/myfolder/", function(html){
$("body").prepend(html);});
I would like to access the DOM in www.example/. There is a form in www.example/. when the submit button of the form is clicked, iw ould like to get the post values in www.mysite. 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扩展程序通信
发布评论