我正在为Gmail创建Chrome扩展程序。无论如何,我已经按照以下方式将https://example.com页加载到扩展中。
到目前为止,内容已加载并且可以正常工作。
现在我想从顶部框架(即Gmail主文档)中获取线程ID或一些与dom相关的ID
我正在尝试在跨源iframe窗口(即example.com iframe窗口)中插入另一个内容脚本,但是我不确定该怎么做?
清单Json:
lapply(names(metalist), function(nm) metalist[[nm]])
背景Js:
{
"name": "gmailext12",
"version": "1.0.0",
"manifest_version": 2,
"description": "gmailext12",
"icons": {
"16": "images/16.png",
"128": "images/128.png"
},
"background" : {
"scripts" : ["scripts/background.js"]
},
"browser_action": {
"default_icon": "images/16.png"
},
"permissions": [
"activeTab",
"tabs",
"identity",
"https://*.google.com/*",
"https://ssl.gstatic.com/",
"https://www.googleapis.com/",
"https://accounts.google.com/"
],
"web_accessible_resources": [
"iframe.html"
]
}
内容脚本:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({file: "scripts/content.js"});
});
iframe html:
var element = document.getElementById('gmail-123');
if (typeof(element) != 'undefined' && element != null)
{
document.getElementById("gmail-123").remove();
}
var extensionOrigin = 'chrome-extension://' + chrome.runtime.id;
if (!location.ancestorOrigins.contains(extensionOrigin)) {
var iframe = document.createElement('iframe');
// Must be declared at web_accessible_resources in manifest.json
iframe.id = 'gmail-123';
iframe.src = chrome.runtime.getURL('iframe.html');
document.body.appendChild(iframe);
}