Get network data in chrome extension - google-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.

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.

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.

How to port Chrome extension to Firefox addon?

I get this error in Firefox:
There was an error during the temporary add-on installation.
Error details ▼
File red_apples.zip does not contain a valid manifest
This is the extension I'm trying to port. Here's the manifest:
{
"manifest_version": 2,
"name": "Red Apples",
"permissions": [
"tabs", "activeTab"
],
"background": {
"persistent": false,
"scripts": [
"background.js"
]
},
"version": "0.0.0.2",
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"browser_action": {
"default_icon": "icon16.png",
"default_title": "Red Apples",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"script.js"
]
}
]
}
At the bottom of this tutorial it says there's a 99% chance it works without modification, if it passes the test here. But it passes the test and still doesn't work.
I get the manifest error both for the version packed with Chrome, and for the version just compressed as .zip.

chrome tabs event don't work on background js

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"
}

Resources