So I tried to write some code which would allow me to take a screenshot of the page when a button is pressed on my website. The code works, but the only problem is that I have to click on the chrome extension first, and then I can click on the button for it to take the screenshot. I guess that's because the active tab is not invoked. Any ideas?
This is the error message:
Unchecked runtime.lastError while running tabs.captureVisibleTab: The 'activeTab' permission is not in effect because this extension has not been invoked.
manifest.json
"permissions": [
"tabs",
"*://google.com/*"
],
background.js
var id = 100;
// Listen for a click on the camera icon. On that click, take a screenshot.
function takeScreenshot() {
chrome.tabs.captureVisibleTab(null, function(screenshotUrl) {
.....
}
chrome.extension.onRequest.addListener(function(request, sender) {
takeScreenshot();
});
contentscript1.js
contentScriptMessage = "Take a screenshot";
document.addEventListener("hello", function(data) { //When overlay is clicked
chrome.extension.sendRequest({message: contentScriptMessage}); //call background script
})
And I pass a message from the webpage when the image is clicked (calls the function go()) like so:
var go = function() {
var event = document.createEvent('Event');
event.initEvent('hello');
document.dispatchEvent(event);
}
Unchecked runtime.lastError while running tabs.captureVisibleTab: The 'activeTab' permission is not in effect because this extension has not been invoked.
This error means that your extension does not have sufficient permissions to access the current tab if there was no explicit user gesture (like a click on your extension). I must say the error is quite misleading here, as you don't have activeTab
permission in your manifest.
Docs mention that you need specifically the "<all_urls>"
permission in order to use this function without explicit invocation. See this bug for an explanation of the requirement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With