从已经 运行 个进程打开 chrome 扩展程序的后台页面
Opening the background page of a chrome extension from an already running proccess
我目前正在编写我的第一个 chrome 扩展程序,它运行 youtube。com/tv 在后台进程中,因此您可以随时使用 phone 或 table 访问它,这工作正常但是如果你想观看视频而不仅仅是听到音频我必须打开后台进程所在的页面,这就是问题开始的地方,因为打开新页面会创建第二个冲突的进程第一次使它们都崩溃,所以我需要知道是否有办法将后台实例打开到可查看的选项卡中。
代码如下:
manifest.json
{
"manifest_version": 2,
"name": "Youtube TV",
"version": "1.0",
"description": "A simple extension which runs 'www.youtube.com/tv' in the background of your browser do you can connect to it with your phone whenever your computer is turned on.",
"background": {
"persistent": true,
"page": "background.html",
"script": "background.js"
},
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/",
"webRequest",
"webRequestBlocking",
"<all_urls>",
"tabs"
]
}
background.html
<html>
<head>
<style type="text/css">
</style>
</head>
<body style="margin:0px">
<script src="background.js"></script>
<iframe style="margin:0px; border:0px" src="http://youtube.com/tv" width="100%" height="100%" >
</iframe>
</body>
</html>
background.js
chrome.webRequest.onHeadersReceived.addListener(
function (details) {
for (var i = 0; i < details.responseHeaders.length; ++i) {
if (details.responseHeaders[i].name.toLowerCase() == 'x-frame-options') {
details.responseHeaders.splice(i, 1);
return {
responseHeaders: details.responseHeaders
};
}
}
}, {
urls: ["<all_urls>"]
}, ["blocking", "responseHeaders"]);
chrome.browserAction.onClicked.addListener(
function (activeTab) {
var newURL = "http://youtube.com/tv";
chrome.tabs.create({ url: newURL });
});
chrome.tabs.create({url: chrome.extension.getURL('background.html')});
编辑
对不起,我没有正确理解这个问题。查看此问题的答案here
The real background page is hidden, and cannot be shown
我目前正在编写我的第一个 chrome 扩展程序,它运行 youtube。com/tv 在后台进程中,因此您可以随时使用 phone 或 table 访问它,这工作正常但是如果你想观看视频而不仅仅是听到音频我必须打开后台进程所在的页面,这就是问题开始的地方,因为打开新页面会创建第二个冲突的进程第一次使它们都崩溃,所以我需要知道是否有办法将后台实例打开到可查看的选项卡中。 代码如下:
manifest.json
{
"manifest_version": 2,
"name": "Youtube TV",
"version": "1.0",
"description": "A simple extension which runs 'www.youtube.com/tv' in the background of your browser do you can connect to it with your phone whenever your computer is turned on.",
"background": {
"persistent": true,
"page": "background.html",
"script": "background.js"
},
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/",
"webRequest",
"webRequestBlocking",
"<all_urls>",
"tabs"
]
}
background.html
<html>
<head>
<style type="text/css">
</style>
</head>
<body style="margin:0px">
<script src="background.js"></script>
<iframe style="margin:0px; border:0px" src="http://youtube.com/tv" width="100%" height="100%" >
</iframe>
</body>
</html>
background.js
chrome.webRequest.onHeadersReceived.addListener(
function (details) {
for (var i = 0; i < details.responseHeaders.length; ++i) {
if (details.responseHeaders[i].name.toLowerCase() == 'x-frame-options') {
details.responseHeaders.splice(i, 1);
return {
responseHeaders: details.responseHeaders
};
}
}
}, {
urls: ["<all_urls>"]
}, ["blocking", "responseHeaders"]);
chrome.browserAction.onClicked.addListener(
function (activeTab) {
var newURL = "http://youtube.com/tv";
chrome.tabs.create({ url: newURL });
});
chrome.tabs.create({url: chrome.extension.getURL('background.html')});
编辑 对不起,我没有正确理解这个问题。查看此问题的答案here
The real background page is hidden, and cannot be shown