Chrome扩展程序,Chrome扩展程序通信

编程入门 行业动态 更新时间:2024-10-28 04:16:10
本文介绍了Chrome扩展程序,Chrome扩展程序通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下是我的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扩展程序通信

本文发布于:2023-08-06 13:10:35,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   通信   Chrome

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!