Powiadomienia
Wyczyść wszystko
BugOverflow
1
Wpisy
1
Użytkownicy
0
Reactions
826
Widoki
0
21/04/2022 8:26 pm
Rozpoczynający temat
example
1 odpowiedź
0
21/04/2022 8:32 pm
Rozpoczynający temat
manifest.json
{
"name": "My extension",
"version": "0.0.5",
"manifest_version": 3,
"description": "my description",
"icons": {
"64": "icon-64.png"
},
"action": {
"default_icon": {
"64": "icon-64.png"
},
"default_title": "Asd Title",
"default_popup": "popup.html"
},
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"],
"run_at": "document_end",
"all_frames": true
}
],
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'"
},
"permissions": [
"tabs",
"management",
"activeTab",
"management",
"browsingData",
"debugger",
"background",
"tabs",
"unlimitedStorage",
"scripting",
"storage"
],
}
popup.html
<!DOCTYPE html> <html> <head> </head> <body> <button id="test_btn" style="width:100px">test btn</button> <input type="text" id="test" name="test"> http://popup.js </body> </html>
popup.js
document.addEventListener('DOMContentLoaded', function() {
let regexBtn = document.getElementById('test_btn')
regexBtn.addEventListener('click', testAction)
});
function testAction(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs)
{
chrome.tabs.sendMessage(
tabs[0].id,
{
some_data: "test_something",
},function (response){});
});
}
content.js
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) =>
{
if (msg.text && (msg.text == "test_something"))
{
console.log("TEST OK");
}
});
