Im new in developing and im developing extension for google chrome, but i have stumbled on issue i cant seem to wrap my head around..
extension works otherwise just as intended but for some websites it stops working after perioid of time.
Error:" Error: The client has been inactive since Mon Jan 10 2022 14:45:38 GMT+0200 (Eastern European Standard Time) and it has exceeded the inactivity timeout of 50000 ms. Stopping the connection. "
Manifestv3.json
{
"manifest_version": 3,
"name": "Add html",
"version": "0.0.01",
"permissions": [
"contextMenus",
"activeTab",
"tabs",
"clipboardRead",
"clipboardWrite"
],
"icons":{
"128": "icon128.png",
"48": "icon48.png",
"16": "icon16.png"
},
"background": {
"service_worker": "eventpage.js"
},
"content_scripts": [ {
"matches": ["<all_urls>"],
"all_frames": true,
"match_about_blank": true,
"js": ["content.js"]
}],
"description": "Adds html to highlighted text in textareas (example <b>XXX</b>)"
}
eventpage.js
chrome.runtime.onInstalled.addListener(function() {
var parent = chrome.contextMenus.create({
"title": 'parent',
"contexts": ["selection"],
"id": "myContextMenuId"
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
console.log("clikki");
console.log(info.selectionText);
if (info.menuItemId.includes('Context')) {
const text = ("<b>"+info.selectionText+"</b>");
console.log(text);
console.log(tab.id);
chrome.tabs.sendMessage(tab.id, text);
}
});
content.js
console.log("Content script is running...");
chrome.runtime.onMessage.addListener(msg => {
console.log("content.js toimii");
console.log( msg );
document.execCommand('insertText', false, msg);
});
console.log ("vituiksmen");
chrome.connection.hub.disconnected(function() {
setTimeout(function() {
console.log("restart");
chrome.connection.hub.start();
}, 5000); // Restart connection after 5 seconds.
});
chrome.connection.hub.disconnected doesent work. Eny suggestion to keep the site active alltho its not visible etc?