I have a ploblem with making Chrome Extention.I got below error in popup.js file:
"Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist." also I live in Iran and I have the internet problem and can not access google documents!!!
please help me to solve this problem. Thanks
this is my code:
1.manifest.json
{
"name": "Hamid Test",
"version": "1.0",
"manifest_version": 3,
"author": "Hamid Solat",
"description": "This is a test",
"icons":{
"128":"/assets/icons/icon.png"
},
"background.service_worker": {
"scripts": ["assets/js/background.js"],
"persistent": false
},
"action": {
"default_icon": "/assets/icons/icon.png",
"default_popup": "popup.html",
"default_title": "Hamid Test"
},
"content_security_policy": {}
,
"permissions": [
"activeTab",
"tabs",
"storage",
"background",
"webNavigation"
]
}
2.popup.html
<!doctype html>
<html>
<head>
<title>Hamid Test</title>
<link rel="stylesheet" href="assets/css/popup.css">
</head>
<body>
<div class="container">
<h1>Hamid Test</h1>
<button id="injectMessage">Send</button>
<div id="validation"></div>
</div>
<script type="text/javascript" src="assets/js/popup.js"></script>
</body>
</html>
3.popup.js
chrome.storage.sync.clear();
let button = document.getElementById("injectMessage");
let validation = document.getElementById("validation");
sleep = async (ms)=>{ return new Promise(resolve => setTimeout(resolve, ms)); }
button.addEventListener("click", async ()=> {
chrome.runtime.sendMessage({"manageMischief": true});
});
4.bacground.js
chrome.runtime.onMessage.addListener((message, sender)=> {
if(!message.manageMischief) return;
else{chrome.tabs.executeScript({
file: 'assets/js/inject.js'
}); }
});
It's the first time I make the chrome extention...
I also try this in popup.js: button.addEventListener("click", async ()=> { alert("OK"); });
it worked.... but my problem is in this line:
chrome.runtime.sendMessage({"manageMischief": true});