chrome tabs event don't work on background js - google-chrome-extension

in my permission
"background": {
"scripts": [ "request.js" ]
},
"browser_action": {
"default_icon": "uefa.png",
"default_popup": "popup.html",
"default_title": "as2"
},
"content_scripts": [ {
"js": [ "content.js" ],
"matches": [ "http://*/*", "https://*/*" ]
} ],
"description": "moving",
"manifest_version": 2,
"name": "as2",
"permissions": [ "http://*/*", "https://*/*", "tabs", "webRequest", "webRequestBlocking", "storage", "webNavigation", "\u003Call_urls>", "cookies" ],
"update_url": "https://clients2.google.com/service/update2/crx",
"version": "1.4",
and request.js
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab)
{
alert("onUpdated"+tab.url);
});
chrome.tabs.onActivated.addListener(function(activeInfo) {
alert("onActivate"+tab.url);
});
chrome.windows.getAll({populate:true},function(windows)
{
windows.forEach(function(window)
{
window.tabs.forEach(function(tab)
{
if(tab.url.indexOf("https://www.bet-at-home.com/en/sport/live/") != -1)
{
alert("ssdsf::"+tab.id);
}
});
});
});
it is works well!
but problem is if without debug window, it never works.
anybody knows about these bug?
it has tabs permission already, and did not work tabs.remove too.

Can you be more specific? I ran your code with a blank popup.html and the following manifest.json and onUpdated worked fine:
{
"background": {
"scripts": [ "request.js" ]
},
"browser_action": {
"default_popup": "popup.html",
"default_title": "as2"
},
"description": "moving",
"manifest_version": 2,
"name": "as2",
"permissions": [ "tabs" ],
"version": "1.4"
}

Related

Issue with creating an extension NativeMessaging in V3: unknow key path and type

I'm trying to make a Chrome extension that opens a local exe (nativeMEssaging) but when I'm trying to load it I have this error: It doesn't know the key path and type so how can I do?
Here is my manifest.json:
{
"name": "debug.reader.eid",
"description": "Console app use to read an eid and send date to extension",
"path": "C:\\debug.reader.eid\\debug.reader.eid.exe",
"type": "stdio",
"externally_connectable": {
"matches": [
"https://*.extranet-test.debug.be/*",
"*://localhost/*"
]
},
"background": {
"service_worker": "background.js"
},
"author": "debug",
"icons": {
"128": "addon-debug.png"
},
"manifest_version": 3,
"permissions": [
"nativeMessaging"
],
"version": "1.0",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"content.js"
],
"run_at": "document_start"
}
],
"action": {
"default_icon": {
"16": "addon-debug.png"
},
"default_title": "test",
"default_popup": "popup.html"
}
}

captureVisibleTab is returning undefined [duplicate]

I am new to the extension development
I have tried with permissions url as
"<all_urls>
"*"
"http://*/*", "https://*/*"
None of the pattern is working
Full manifest:
{
"name": "Info",
"description": "BS System Info",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"content_scripts": [{
"js": ["script.js"],
"matches": ["http://*/*","https://*/*","<all_urls>"],
"css" : []
}],
"permissions": [
"storage",
"activeTab",
"system.cpu",
"system.memory",
"system.storage",
"system.display",
"tabs",
"scripting",
"http://*/*", "https://*/*", "chrome-devtools://*/*"
],
"action": {
"default_popup": "index.html",
"default_icon": {
"16": "/images/icon_16.png",
"32": "/images/icon_32.png",
"48": "/images/icon_48.png",
"128":"/images/icon_128.png"
}
}
}
Site/URL permissions in ManifestV3 use a separate key: host_permissions
"host_permissions": [
"*://*.example.org/"
],
"permissions": [
"storage"
],
More info in the official migration guide, make sure to study it.

Get network data in chrome extension

I have a chrome extenison but i can't figure out how to access the data in the devtools network tab and send to the popup. Any suggestion?
it's basically a bug reporting chrome extension where you can take screenshots, create issue, and I need the network log (and/or console)
manifest.json
{
"manifest_version": 2,
"name": "my-chrome-extension",
"description": "Chrome Extension for report bug",
"version": "1.0",
"background": {
"scripts": [
"js/background.js"
],
"persistent": false
},
"icons": {
"16": "./icon.png",
"36": "./icon.png",
"48": "./icon.png",
"120": "./icon.png"
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"js/vendor.js", "js/content_script.js"
]
}
],
"web_accessible_resources": [
"inject-script.js",
"js/inject-script.js"
],
"browser_action": {
"default_popup": "popup.html",
"default_title": "PerfWatch"
},
"permissions": [
"tabs",
"activeTab",
"storage"
]
}
You cant access it directly. Only via API like webRequest via bg script.
Example:
chrome.webRequest.onBeforeRequest.addListener((details) => {
//This identifies a redirect to another page
if (details.url.indexOf("Target") && details.method === "OPTIONS/..." && details.initiator.indexOf("Source")) {
chrome.tabs.sendMessage(details.tabId, {
message: "xyz"
});
}
})
Your manifest.json must include the webRequest permission in order to access the webRequests:
{
"manifest_version": 2,
"name": "my-chrome-extension",
"description": "Chrome Extension for report bug",
"version": "1.0",
"background": {
"scripts": [
"js/background.js"
],
"persistent": false
},
"icons": {
"16": "./icon.png",
"36": "./icon.png",
"48": "./icon.png",
"120": "./icon.png"
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"js/vendor.js", "js/content_script.js"
]
}
],
"web_accessible_resources": [
"inject-script.js",
"js/inject-script.js"
],
"browser_action": {
"default_popup": "popup.html",
"default_title": "PerfWatch"
},
"permissions": [
"tabs",
"activeTab",
"storage",
"webRequest"
]
}
Hint:
There are additional APIs like webNavigation and webRequestBlocking if you need more funtionallity.

chrome extention chrome.webRequest no information was obtained [duplicate]

I am new to the extension development
I have tried with permissions url as
"<all_urls>
"*"
"http://*/*", "https://*/*"
None of the pattern is working
Full manifest:
{
"name": "Info",
"description": "BS System Info",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"content_scripts": [{
"js": ["script.js"],
"matches": ["http://*/*","https://*/*","<all_urls>"],
"css" : []
}],
"permissions": [
"storage",
"activeTab",
"system.cpu",
"system.memory",
"system.storage",
"system.display",
"tabs",
"scripting",
"http://*/*", "https://*/*", "chrome-devtools://*/*"
],
"action": {
"default_popup": "index.html",
"default_icon": {
"16": "/images/icon_16.png",
"32": "/images/icon_32.png",
"48": "/images/icon_48.png",
"128":"/images/icon_128.png"
}
}
}
Site/URL permissions in ManifestV3 use a separate key: host_permissions
"host_permissions": [
"*://*.example.org/"
],
"permissions": [
"storage"
],
More info in the official migration guide, make sure to study it.

Cannot read property 'onConnet'

I'm attempting to follow the documentation here to pass a variable from my background script, to my content script.
http://code.google.com/chrome/extensions/messaging.html
Manifest:
{
"name": "name",
"description": "desc",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*" ],
"js": ["content.js"]
}
],
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
],
"options_page": "options.html",
"browser_action":
{
"default_icon": "icon.png",
"default_title": "Settings",
"default_popup": "settingspanel.html"
}
}
background.js file:
chrome.extension.onConnect.addListener(function(port) {
port.onMessage.addListener(function(msg) {
port.postMessage({counter: msg.counter+1});
});
});
content.js
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
sendResponse({counter: request.counter+1});
});
I receive an error on the background script that says "Cannot read property 'onConnect' of undefined"
Probably your problem is Issue #131623: Reloading extension while developer tools are open breaks chrome object and js console.
Until the fix gets through you have to close the Developer Tools before reloading the extension.

Resources