Problem: Uncaught TypeError: Cannot read property 'onUpdated' of undefined
Google Chrome extension
My code:
main.js
I have a function getCookie and setcookie
var _a = getCookie("a");
if (_a != "") {
/// do something
} else {
chrome.tabs.onUpdated.addListener(function(tabId , info , tab) {
if (info.status == "complete") {
var _a = document.getElementsByName('id_loaded_page')[0].value;
setCookie("_a", value, 1);
console.log("_a: " +_a);
}
});
}
You are calling chrome.tabs
from a Content Script.
By design, content scripts are not allowed access to most of the Chrome APIs.
You need to make a background page to access chrome.tabs
, but in your particular case you don't even need that wrapper: you're injecting at "document_end"
, which should mean that all static DOM is already loaded
And if the DOM node you are looking for is dynamically added, it may not exist when "complete" fires for a tab. You will need to listen to DOM mutations.
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