I am new to chrome extensions, and I am trying to create a simple extension that closes the current tab if the element class matches.
This is my code in the content of the script:
$(document).ready(function() { if ($(".watchdogedit").length > 0) { setTimeout(CLOSECURRENTAB,3000); } });
I need a CLOSECCURENTTAB function.
Help me!
EDIT:
DONE!
content script:
$(document).ready(function(){ if ($(".watchdogedit").length > 0) { setTimeout(closeTab, 3000); } }); function closeTab() { chrome.runtime.sendMessage({type: "closeTab"}); }
background script:
chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { if (request.type == "closeTab") { chrome.tabs.remove(sender.tab.id); } } );
source share