Trying to disable extension from web page - google-chrome

Here I have taken permission for all the needed thing, if something missing here please let me know.
Manifest.json
{
"manifest_version": 2,
"name": "SearchMood",
"description": "This extension shows Google Web Search and Google Image
Search result.",
"version": "1.4",
"author":"Searchmood",
"browser_action": {
"default_icon": {
"128": "icon-128.png",
"16": "icon-16.png",
"48": "icon-48.png"
},
"default_title": "SearchMood",
"default_popup": "background.html"
},
"chrome_url_overrides" : {
"newtab": "popup.html"
},
"icons": {
"128": "icon-128.png",
"16": "icon-16.png",
"48": "icon-48.png"
},
"background": {
"scripts": [ "background.js","popup.js" ]
},
"permissions": [
"activeTab","management","https://ajax.googleapis.com/"
],
"content_scripts": [
{
"matches": [ "http://search.searchmood.com/*" ],
"js": [ "js/restoremodal.js" ],
"all_frames": true,
"run_at": "document_start"
}
],
"externally_connectable": {
"matches": ["http://*.searchmood.com/*"]
}
}
Script on my web page I have:
<div class="links">
<ul>
<li>Terms&Conditions</li> |
<li>Privacy policy</li>|
<li>Contact US</li>
<li><span id="restoreLink" onclick="adi();">Reset Chrome</span></li>
</ul>
</div>
<script type="text/javascript">
function adi(){
var editorExtensionId = "pokioadkjpcbalcpfidmlebofahebkhb";
// Make a simple request:
chrome.runtime.sendMessage(editorExtensionId, {request: "uninstall"});
}
</script>
And this is the code in my extension to listen To this message I have put this code in popup.js. Please guide me where to put that also.
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
if (request == "uninstall") {
var id = chrome.app.getDetails().id;
chrome.management.setEnabled(id, false);
}
});
This the script I have written. I have some other codes also but that is also not working.

Yes I got the answer In the content Script File We can write code for taking the element from Website And their we will use SendMessage function Make sure You have taken permission for "Management" in manifest.json And persistent in Menifest.json should be "false".
Then you can use onmessage function and disable your extension Codes for your reference:
**HTML**`<span id="restorelink"> disable chrome extension</span>`
**menifest.json**
{
"manifest_version": 2,
"name": "name",
"description": "describe about you extension",
"version": "1",
"browser_action": {
"default_icon": {
"128": "icon-128.png",
"16": "icon-16.png",
"48": "icon-48.png"
},
"background": {
"scripts": [ "background.js"],
"persistent": false
},
"permissions": [
"management"
],
"content_scripts": [
{
"matches": [ "http://your site url where you want to apply the change, you can use more than one seperating with "," ],
"js": [ "restoremodal.js" ],
"all_frames": true
}
]
}
**restoremodal.js**
document.getElementById("restoreLink").addEventListener("click", adi);
function adi(){
chrome.runtime.sendMessage({ value: "anything"});
}
**Background.js**
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.value=="anything") {
var id = chrome.app.getDetails().id;
chrome.management.setEnabled(id, false);
}
});

Related

Chrome Extension background.js not receiving message sent from content.js

I want to send data from my inject.js to background.js so that it calls for an external API to store the data into DB.
Here are my sample files
manifest.json
{
"name": "Income Tax Notice Reader",
"description": "Reads Income Tax notices once you login into the IT account",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"alarms",
"notifications",
"activeTab",
"tabs",
"storage",
"scripting"
],
"background": {
"service_worker": "background.js"
},
"content_scripts": [{
"exclude_globs": [
"chrome://extensions/"
],
"matches": [
"<all_urls>"
],
"all_frames": true,
"js": ["jquery.min.js","content.js"]
}],
"web_accessible_resources": [{
"resources": ["inject.js","jquery.min.js"],
"matches": [ "<all_urls>" ]
}],
"action": {},
"icons": {
"16": "favicon.ico"
},
"commands":{
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+F",
"mac": "MacCtrl+Shift+F"
}
}
}
}
My content.js file
var script = document.createElement('script');
script.src = chrome.runtime.getURL('jquery.min.js');
(document.head||document.documentElement).appendChild(script);
var script = document.createElement('script');
script.src = chrome.runtime.getURL('inject.js');
(document.head||document.documentElement).appendChild(script);
window.addEventListener("message",function(event){
alert(event.data.message);
chrome.runtime.sendMessage(event.data);
return true;
});
Background.js
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ['content.js']
});
}
})
chrome.runtime.onMessage.addListener(function(event){
console.log(event.data.message);
return true;
});
inject.js
window.postMessage({message:"send message to background worker"});
The message is reaching till content.js, but it is not going from content.js to background.js, not sure what I am doing wrong here, tried multiple ways but still failing to understand the issue.

"Cannot access contents of url" Chrome extension error in background.js

I am trying to invoke a current_script from a background script, but I receive the following error:
Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "chrome-devtools://devtools/bundled/inspector.html?
I understand I need to send also tab.id in executeScript function, I also tried that but with no luck.
UPDATE: I changed background.js to the following but content_script.js is still not working:
chrome.commands.onCommand.addListener(function(command) {
if (command === "toggle-feature") {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
for(var i = 0; i<tabs.length;i++) {
alert(tabs.length);
chrome.tabs.executeScript(tabs[i].id, {"file": "content_script.js"});
alert("h");
}
});
}
});
Here is all my code:
Manifest.nmf
{ "manifest_version": 2,
"name": "Extractor",
"version": "1",
"description": "Extract from 144",
"icons": {
"16": "logo16.png",
"48": "logo48.png",
"128": "logo128.png"
},
"page_action": {
"default_icon": {
"16": "logo16.png",
"48": "logo48.png",
"128": "logo128.png"
},
"default_title": "Extractor"
},
"background": {
"scripts": [ "background.js" ],
"persistent": true
},
"content_scripts": [ {
"matches": [ "https://www.msn.com/*" ],
"js": [ "content_script.js" ]
} ],
"permissions": [
"tabs",
"https://www.msn.com/*",
"activeTab",
"*://*/*"
],
"commands": {
"toggle-feature": {
"suggested_key": {
"default": "Ctrl+Shift+1",
"windows": "Ctrl+Shift+2"
},
"description": "Extract now"
}
}
}
Background.js
chrome.commands.onCommand.addListener(function(command) {
if (command === "toggle-feature") {
chrome.tabs.executeScript(null, {file: "content_script.js"} );
}
});
content_script.js
alert("success");
As you see I have also tried to add all links combinations in permissions but with no luck!
How can I solve this problem and get current_script working when pressing a hot key in a tab?

background.js is being triggered every refresh

It seems as if my background.js is triggered every refresh [planted an alert, and i see it every refresh, also my context menu is duplicating its inner self].
this is my manifest file:
"manifest_version": 2,
"name": "test",
"description": "test",
"version": "1.0",
"permissions": [
"activeTab",
"storage",
"tabs",
"contextMenus",
"https://*/*",
"http://*/*",
"https://www.google.com/_/chrome/newtab*"
],
"browser_action": {
"default_icon": "raj_robot.png",
"default_title" : "MemoMi"
},
"chrome_url_overrides" : {
"newtab" : "mypage.html"
},
"background": {
"scripts" : ["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js" : ["selection.js"],
"run_at": "document_end"
}
],
And this is my background script:
function handle_click() {
alert("hi there!");
}
chrome.contextMenus.create({
title: "menu title",
contexts:["selection"],
onclick: handle_click
});
what am I doing wrong here?
Thanks!
Gura
Ok, I found it. I was actually implicitly triggering background.js by using methods in the content scripts, that should have been in the background.js. Just comment out your code and and see if it improves.

manifest.json:34:1: an object must end with '}'

I have developed an extension and trying to upload it. but it gives error:manifest.json:34:1: an object must end with '}'.
Any help will be appreciated.
here is the content of manifest.json:
{
"manifest_version" :2,
"name": "Text to Speech",
"version" :"1.0.0",
"description" :"Indian language text to speech extension. Developed under TDIL programme by TTS consortium",
"options_page": "options.html",
"browser_action": {
"default_icon": { // optional
"19": "images/text2voice.png" // optional
},
"default_title": "Indian language TTS", // optional; shown in tooltip
"default_popup": "popup.html" // optional
},
"icons": { "16": "images/t2v-48.png",
"48": "images/t2v-48.png",
"128": "images/t2v-128.png" },
"background": {
"page": "background.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"], //content script will be injected in all urls
"js": ["content_script.js"]
}
],
"permissions": [ //permitted to access following pages
"http://*/*",
"https://*/*",
"contextMenus",
"tabs"
]
}
Your comments such as //options is breaking your json. Please try to put the entire contents of manifest.json validator(http://jsonlint.com) and see the errors.

chrome browserAction to pageAction

this works fine in browserAction..
but when i switch it pageAction.. even the icon doesnot show up
background.html
<html>
<head>
<script>
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({'url':'http://google.com/search?q=site:'+window.location.host});
});
</script>
</head>
</html>
manifest.json
{
"name": "linkcheck",
"description": "check link.",
"version": "1.1.1",
"
background_page": "background.html",
"permissions": ["tabs", "http://*/*","https://*/*"],
"browser_action": {
"name": "linkcheck",
"default_icon": "icon.png"
},
"icons": {
"128": "icon128.png",
"48": "icon48.png"
},
"content_scripts": [
{
"matches": ["https://www.google.com/*"],
"js": ["myscript.js"],
"run_at": "document_end"
}
]
}
Well for pageAction, you would need to enter another manifest property:
{
"name": "My extension",
...
"page_action": {
"default_icon": "icons/foo.png", // required
"default_title": "Do action", // optional; shown in tooltip
"default_popup": "popup.html" // optional
},
...
}
Then you need to either hide or show.
chrome.pageAction.show(integer tabId)