Im trying to create a quite simple chrome extention, that close a pop-up after the pop-up is loaded, and by its title.
But for some reason the the title keeps returnen blank.
This is what i came up with.
{
"name": "ReportCloser",
"version": "0.1",
"permissions": [
"tabs","<all_urls>"
],
"browser_action": {
"default_icon": "icon.png"
},
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
"run_at": "document_end" ,
"js": ["script.js"] // pay attention to this line
}
],
"manifest_version":2
}
script.js
var x = document.title;
var title = "customtitle";
if(x==title){
close();
}
else{ }
I tried to move run_at: document_end before the content script, but the problem i still there.
Any tips?
Related
I'm trying to make an extension to work on all the site.And also for some site specific sites(Google and LinkedIn) I want some others action to be performed. I have managed to work it on Google search google.com/search and LinkedIn search pages linkedin.com/vsearch/ and perform action A and B respectively. But i'm stuggling to make it work on all others sites to perform action C.
{
"manifest_version": 2,
"name": "extname",
"description": "Welcome to my ext",
"icons": {
"48": "images/ext.png"
},
"version": "2.6",
"background": {
"scripts": [ "js/jquery-2.1.4.min.js", "js/background.js","js/select2.min.js","js/lodash.js","js/bootstrap.min.js","js/bootstrap-select.min.js" ]
},
"content_scripts": [{
"css": [ "css/select2.css" ,"css/bootstrap.min.css","css/bootstrap-select.min.css" ],
"js": [ "js/jquery-2.1.4.min.js", "js/extension_google_result.js" ,"js/select2.min.js" ,"js/bootstrap.min.js","js/bootstrap-select.min.js"],
"matches": [ "*://*.google.com/search*" ] //for Google Search page
},
{
"css": [ "css/extension_linkedin_search_page.css", "css/bootstrap.min.css","css/bootstrap-select.min.css" ],
"js": [ "js/jquery-2.1.4.min.js","js/select2.min.js" ,"js/bootstrap.min.js","js/bootstrap-select.min.js"],
"matches": [ "*://*.linkedin.com/vsearch/*"] //for Linkedin Search page
},
{
"css": [ "css/extension_linkedin_search_page.css" ,"css/bootstrap.min.css","css/bootstrap-select.min.css","css/select2.css" ],
"js": ["js/lodash.js", "js/jquery-2.1.4.min.js", "js/extension_linkedin_sales_navigator_search_page.js" ,"js/select2.min.js" ,"js/bootstrap.min.js","js/bootstrap-select.min.js", "js/akash.js"],
"matches": [ "<all_urls>"] //for all other sites
}
],
"content_security_policy": "script-src 'self' 'unsafe-eval' https://d37gvrvc0wt4s1.cloudfront.net https://*.pusher.com; object-src 'self'",
"browser_action": {
"default_icon": "images/found128.png",
"default_popup": "html/extension-login-popup.html",
"default_title": "Search with Found"
},
"permissions": ["cookies","tabs", "http://*/*", "https://*/*","contextMenus", "tabs", "storage", "\u003Call_urls>", "notifications", "webRequest" ]
}
But here the first two cases for google and linked in search works perfectly and i'm getting callbacks(Action A and B) on only those pages as expected.I'm also able to call action c on other sites.But actin c is also been calling on google and linkedIn search pages also on every new tab action which i don't want.How can i fix that? Any idea?
Take a look at Content Scripts, you will find you can use exclude_matches in your manifest.json to exclude pages that your content script would not be injected into.
I'm trying to build a basic extension that injects an alert script in to every page loaded. But it seems that the script is injecting only to some pages (most pages it's not injected in to), and I couldn't find a pattern in how it picks the pages to get injected to.
This is the manifest:
{
"name": "TestingTest",
"version": "0.1.1",
"description": "Testing Tests!",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["http://*/", "https://*/"],
"js": ["content.js"],
"run_at": "document_end"
}
],
"background": {
"page": "background.html"
},
"permissions": [
"tabs",
"http://*/", "https://*/",
"cookies"
],
"icons": {
"16": "my_icon_64.png",
"32": "my_icon_64.png",
"48": "my_icon_64.png",
"128": "my_icon_64.png"
}
}
and this is ccontent.js:
alert("content script");
console.log("content script")
I'm getting the alert only on a select few pages. The pages that it's injected in to seem to vary if I load the extension in different Chrome profiles.
Your content script is probably loading only on pages where the pathname is just /. Add an extra * at the end of your url patterns:
"matches": ["http://*/*", "https://*/*"]
after reading the tutorials I still can't make my extension to work after clicking on it, it starts working as soon as the page loaded.
Here is my manifest.
{
"manifest_version": 2,
"name": "My extension",
"description": "This extension bla bla.",
"version": "3.0",
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"browser_action": {
"default_icon": "icon.png"
},
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["make_changes.js"]
}
],
"background": {
"scripts": ["make_changes.js"],
"persistent": false
}
}
and here is my make_changes.js:
var oldSource = document.documentElement.innerHTML;
document.body.innerHTML = Make_change(oldSource);
function Make_change(source){
...
}
I've also got the background.HTML file, but it works without it. It seems that it is not correct:
chrome.tabs.executeScript(null, {file: "make_changes.js"});
You need to add a listener for the browser action onClicked event:
http://developer.chrome.com/extensions/browserAction.html#event-onClicked
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(tab.id, {file: "make_changes.js"});
});
I'm creating a chrome extension but I'm having some difficulties in use notifications webkit. When I try to display a notification, an exception is thrown:
Uncaught Error: SecurityError: DOM Exception 18
Bellow follow my Javascript code:
var icon = 'icon_48.png';
var title = 'Test Plugin';
var body = message;
var popup = window.webkitNotifications.createNotification(icon, title, body);
popup.show();
Bellow follow my manifest.json:
{
"name": "Test Plugin",
"version": "1.0.6",
"manifest_version": 2,
"description": "This is a test",
"browser_action": {
"default_icon": "images/icon_32.png",
"default_popup": "popup.html"
},
"icons": {
"128": "images/icon_128.png",
"16": "images/icon_32.png",
"48": "images/icon_48.png"
},
"permissions": [
"http://*/*",
"https://*/*",
"contextMenus",
"tabs",
"notifications",
"management",
"webRequest"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["webtoolkit-sha1.js","content.js"],
"run_at": "document_end",
"css" : ["css/style.css"]
}
],
"web_accessible_resources": ["webtoolkit-sha1.js","inject.js","icon_48.png"]
}
What am I doing wrong?
Thanks everybody!
Information Update:
manifest.json has the attribute notifications in permissions section but when I print the webkitNotifications.checkPermission() the result was 1 (PERMISSION_NOT_ALLOWED).
The notifications permission only applies to the extension's process. In order to get your code to work, a background (or event) page needs to be added, which creates the notification. The content script can use the messaging API to request the notification.
In the above screenshot you will see a panel and there are three buttons namely hide, close and clear.
I want to perform a particular action on click of those buttons.
Can you please suggest me some approach to achieve it?
Actually the panel created below is nothing but a div container which I have appended to the body of the current webpage.
So I had tried with one approach to inject my own script in that particular webpage and perform a particular action on those button clicks.
But that didn't work for me.
Can you please suggest me some other approach?
This is my manifest file :-
{
"name": "Demo Extension",
"version": "1.0.0",
"manifest_version": 2,
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": ["jquery-1.7.2.js","code.js"]
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["jquery-1.7.2.js","content.js"],
"css": ["panel.css"],
"run_at": "document_end"
}
],
"permissions": [
"webRequest",
"tabs",
"http://*/*",
"https://*/*",
]
}
And my content.js file is as follows:
var data_div = $("<div class='panel'></div>");
data_div.css("position","fixed");
data_div.css("bottom","0px");
data_div.css("height","300px");
data_div.css("display","block");
data_div.css("width","100%");
data_div.css("overflow","scroll");
data_div.css("z-index","1004");
data_div.css("background-color","#C0C0C0");
$("body").append(data_div);
data_div.html("One big data set here");