忽略第一个水平规则以下的所有内容 - 短篇小说这是一个 CSP 问题,但 Rob W 的解决方案要好得多:
manifest.json
{
"name": "Todoist Gmail Sidebar",
"manifest_version": 2,
"description": "Toggle a Todoist sidebar on the gmail tabs when the page action is clicked",
"version": "0.9",
"homepage_url": "http://turkeyphant.org",
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"permissions": [ "tabs",
"https://*/*","http://*/*","activeTab"
],
"background":{
"persistent":true,
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "icon128.png",
"default_title": "Toggle Todoist sidebar"
},
"content_scripts": [
{
"js": [
"jquery.min.js",
"jquery.easing.1.3.js",
"contentscript.js"
],
"matches": [
"*://mail.google.com/*"
],
"run_at": "document_end"
}
],
"web_accessible_resources": [
"frame.html",
"toggleSidebar.js"
]
}
contentscript.js
if (typeof sidebarOpen == 'undefined') { //if not set yet, it's closed
console.log("sidebar initiated");
sidebarOpen = false; //set closed
var width = '400';//variables
//resolve html tag, which is more dominant than <body>
var html;
if (document.documentElement) {
html = $(document.documentElement); //just drop $ wrapper if no jQuery
} else if (document.getElementsByTagName('html') && document.getElementsByTagName('html')[0]) {
html = $(document.getElementsByTagName('html')[0]);
} else if ($('html').length > -1) {//drop this branch if no jQuery
html = $('html');
} else {
alert('no html tag retrieved...!');
throw 'no html tag retrieved son.';
}
//position
if (html.css('position') === 'static') { //or getComputedStyle(html).position
html.css('position', 'relative');//or use .style or setAttribute
}
// Avoid recursive frame insertion...
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.src = chrome.runtime.getURL('frame.html');
iframe.className = 'todo-sidebar';
// Some styles for a fancy sidebar
iframe.style.cssText = 'position:fixed;top:0;right:-'+width+'px;display:block;width:'+width+'px;height:100%;z-index:1000;border-width: 0px 0px 0px 0px;';
document.body.appendChild(iframe);
}
}
frame.html
<iframe id="iframe-sidebar" src="https://todoist.com/"></iframe>
然后你可以在toggleSidebar.js中放任何你想要的东西。
因此,经过进一步调查,问题似乎出在 Gmail 中,它阻止了来自某些域的 iframe 内容:
拒绝框架“https://todoist.com/”,因为它违反了以下内容安全政策指令:“frame-src https://.talkgadget.google.com/ 'self' https://accounts.google.com/ https://apis.google.com/u/ @987654324 @ @https://content.googleapis.com/static/ https://mail-attachment.googleusercontent.com/ https://www.google.com/calendar/ https://docs.google.com/ https://drive.google.com https://.googleusercontent.com/docs/securesc/ https://feedback.googleusercontent.com/resources/ https://www.google.com/tools/feedback/ https://*.googleusercontent.com/gadgets / IFR https://talkgadget.google.com/u/ 987654333 https://isolated.mail.google.com/mail/ 987654335 https://plus.google.com/ 987654337 https://www.youtube.com/embed/ 987654339 https://clients5.google.com/ads/measurement/jn/ 987654341 https://clients5.google.com/webstore/wall/ 987654343 https://apis.google.com/additnow/”。
但是,我无法弄清楚为什么一个 Gmail 帐户会阻止这个,而另一个却没有。也不是这个列表来自哪里,或者我如何为我的扩展覆盖/更改它。