admin 管理员组文章数量: 1086019
I have a simple method which captures current tab, and it works only when this method triggered by click on extension button (i.e. browserAction).
But when I use this method in setTimeout event it fails with following error:
Unchecked runtime.lastError while running tabCapture.capture: Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured.
My simple capture method is:
function captureTab() {
var constraints = ...
chrome.tabCapture.capture(constraints, function (stream) {
if (!stream) {
console.error("couldn't record tab");
return;
}
// recording succeeded
});
}
And it works when it triggered as follows:
chrome.browserAction.onClicked.addListener(function () {
chrome.tabs.getSelected(null, function (tab) {
captureTab();
});
});
But doesn't work when it triggered as follows:
setTimeout(function () {
chrome.tabs.getSelected(1, function (tab) {
captureTab();
});
}, 1 * 30 * 1000);
Important note: My extension isn't a public extension and it runs only on my browser so I can add any mand line switch on start (in order to disable this limitation), if needed.
I have a simple method which captures current tab, and it works only when this method triggered by click on extension button (i.e. browserAction).
But when I use this method in setTimeout event it fails with following error:
Unchecked runtime.lastError while running tabCapture.capture: Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured.
My simple capture method is:
function captureTab() {
var constraints = ...
chrome.tabCapture.capture(constraints, function (stream) {
if (!stream) {
console.error("couldn't record tab");
return;
}
// recording succeeded
});
}
And it works when it triggered as follows:
chrome.browserAction.onClicked.addListener(function () {
chrome.tabs.getSelected(null, function (tab) {
captureTab();
});
});
But doesn't work when it triggered as follows:
setTimeout(function () {
chrome.tabs.getSelected(1, function (tab) {
captureTab();
});
}, 1 * 30 * 1000);
Important note: My extension isn't a public extension and it runs only on my browser so I can add any mand line switch on start (in order to disable this limitation), if needed.
Share Improve this question asked Mar 14, 2016 at 10:39 urieluriel 1,2481 gold badge16 silver badges26 bronze badges3 Answers
Reset to default 5Please be aware chrome.tabCapture.capture can only be started on the currently active tab after the extension has been invoked.
Captures the visible area of the currently active tab. Capture can only be started on the currently active tab after the extension has been invoked.
And when you declare activeTab permissions, only the following user gestures enable it
- Executing a browser action
- Executing a page action
- Executing a context menu item
- Executing a keyboard shortcut from the mands API
- Accepting a suggestion from the omnibox API
So when you are using setTimeOut
, you can not ensure current tab is active.
I know this is weird I'm answering my own question after I accepted a different answer, but...
I have a solution for that which can be applied only if you can inject switch to chrome which in my case is possible as I noted above:
Important note: My extension isn't a public extension and it runs only on my browser so I can add any mand line switch on start (in order to disable this limitation), if needed.
So the trick is to use the follwoing switch with your extension id:
--whitelisted-extension-id="abcdefghijklmnopqrstuvwxyz"
Hope this will help someone someday.
The method that works is a user action invoking your extension (someone clicks something that tells Chrome it's okay because the user wanted it).
This temporarily grants "activeTab" permissions to the extension and is why it is working. (https://developer.chrome./extensions/activeTab)
To make it work like you intend (without an action bringing the activeTab permissions in automatically), you would need to declare it in your extension's permissions section, for example:
"permissions": [
"tabs",
"bookmarks",
"http://www.blogger./",
"http://*.google./",
"unlimitedStorage",
"activeTab"
],
see https://developer.chrome./extensions/declare_permissions
本文标签: javascriptCapture chrome tab without browse actionStack Overflow
版权声明:本文标题:javascript - Capture chrome tab without browse action - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744055885a2525838.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论