Bookmarks permission for Google Chrome - google-chrome

I currently looking to build a Google Chrome Extension that fetches bookmarks from the the browser and sent them to server from synchronization perspective,but it seem to always complain me of "permission error" for the "API method" used in "background.html", even though I have set the necessary permission in "manifest.json"
Here what my manifest.json look like
{
"name" : "Sync BookMark",
"background_page": "background.html",
"version" : "1.0",
"content_script" : {
"css" : ["bookmark.css"],
"js" : ["js/jquery.js","js/bookmark.js"]
},
"browser_action" : {
"default_icon" : "images/bookmark.png",
"default_title" : "Syn Bookmark",
"default_popup" : "bookmark.html"
},
"permission" : [
"bookmarks",
"management",
"unlimitedStorage"
]
}
And Here my background.html code
chrome.bookmarks.getTree(function(bookmarks) {
printBookmarks(bookmarks);
});
function printBookmarks(bookmarks) {
bookmarks.forEach(function(bookmark) {
console.debug(bookmark.id + ' - ' + bookmark.title + ' - ' + bookmark.url);
if (bookmark.children)
printBookmark(bookmark.children);
});
}
// The above code is used from the following link
Now if try to debug the above code in the Chrome developer console
It return a error of permission of the API methods used.

Got it I just miss an 's' in permission i.e "permission" instead of "permissions"

Related

How to add Leverage browser caching to firebase.json

I'm using Firebase on Google Cloud Platform for the first time and I've uploaded my static website but now I'd like to add:
"headers": [ {
"source" : "**/*.#(eot|otf|ttf|ttc|woff|font.css)",
"headers" : [ {
"key" : "Access-Control-Allow-Origin",
"value" : "*"
} ]
}, {
"source" : "**/*.#(jpg|jpeg|gif|png)",
"headers" : [ {
"key" : "Cache-Control",
"value" : "max-age=7200"
} ]
}, {
// Sets the cache header for 404 pages to cache for 5 minutes
"source" : "404.html",
"headers" : [ {
"key" : "Cache-Control",
"value" : "max-age=300"
} ]
} ]
to enable Leverage browser caching, but I do not understand how to add these lines of code to the firebase.json file?
The firebase init command creates a firebase.json settings file in the root of your project's directory, but how can I change it after I've created the site?
Thanks a lot
If you want to change the caching settings on your web site, change the relevant Change-Control header in your firebase.json and then rerun firebase deploy. This will deploy the latest firebase.json with your new settings, and ensure that all HTML/CSS/JS/etc files are up to date too.
If you lost your firebase.json, a simple default could look something like this from the Firebase Hosting reference documentation:
{
"hosting": {
"public": "app",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}

console.log(document) through content script returns html elements in content script console a bit different than inspect page console

console.log(document) through content script returns html elements in content script console a bit different than inspect page console
suppose i am developing content script for a web page and when i inspect the page using chrome i get following elements
<button id="btn">click me<button/>
<input id="prc" value=8181/>
and when i check this html document through my content script just using following code :
console.log(document)
then i am not getting all the elements in the console :
<button id="btn">click me<button/>
(probably missing input element or some others)
I've tried many solutions regarding page loading but nothing is working.
here's manifest.json :
{
"name": "Sarkar Communication Stocks Updater",
"description" : "This extension asks sarkarians to decide whether certain parts are physically consumed or not while call closing",
"version": "1.0",
"manifest_version": 2,
"icons" : { "128" : "SC_logo_128.png"},
"permissions" : [
"http://sapgwprd.lavapartners.in:8000/*",
"tabs"
],
"browser_action" : {
"defaul_title" : "Sarkar Communication Stock Updater",
"icons" :
{
"128" : "SC_logo_128.png",
"16" : "SC_logo_16.png"
}
},
"content_scripts" : [
{
"matches" : [
"http://sapgwprd.lavapartners.in:8000/*"
],
"js" : ["content.js"],
"run_at" : "document_end"
}
]
}

Chrome Extension - Event Pages/Message Passing is not working

I'm novice in Google Chrome Extension development and I'm running through an issue which is causing the content script not getting executed. Below is a detailed description of the issue.
I'm working an extension to read some DOM content from a web site per say example.com I've the following files and the respective code part of it.
manifest
{
"manifest_version" : 2,
"name" : "My First Chrome App",
"description" : "My First Chrome App",
"version": "1.0",
"browser_action" : {
"default_title" : "Hello"
},
"permissions" : ["tabs"],
"background" : {
"scripts" : ["background.js"],
"persistence" : false
},
"content_scripts":[
{
"matches": [
"http://example.com/HomePage.aspx"
],
"js": ["jquery_224.js", "content_script.js"]
}]
}
background.js
My intention is to create a tab and surf to a page which is mentioned in the below script. And, it has to send a message to content_script.js
chrome.browserAction.onClicked.addListener(function(){
chrome.tabs.create({ url: "http://example.com/HomePage.aspx" }, function(tab){
chrome.runtime.sendMessage({authKey : "parse-dom"});
setTimeout(function(){
chrome.tabs.remove(tab.id);
}, 2000);
});
});.
content_script.js
Here I'm trying to read the authKey that I'm sending it from my background.js
chrome.runtime.onMessage.addListener(function(request,sender,response){
alert(request.authKey);
});
Unfortunately, I'm not getting the alert nor seeing any script errors. I have gone through the Chrome Messaging API and followed the same
Where am I going wrong?
Try with
"content_scripts":[
{
"run_at": "document_start",
More infos: https://developer.chrome.com/extensions/content_scripts
or try putting a timeout on your background sendMessage
EDIT: I've also noticed on manifest.json you have an HTTPS match while you are creating a tab with an HTTP address

Chrome extension executescript into external drive file

I have created an extension that uses the executescript api to inject a piece of code (shown below) that basically on window.onbeforeunload confirms they want to close the page. I have the script working, and by using the file://*/* permission, got it to inject on file URLs. However, when testing it on a flash game I downloaded, the script didn't inject. The URL was externalfile:drive-randomtext/root/SWFNAME.swf. I tried adding externalfile://*/* in the permissions but got the following error message: There were warnings when trying to install this extension: Permission 'externalfile://*/*' is unknown or URL pattern is malformed. Is there an external file permission, or another way to do this?
Manifest.json:
{
"name": "name",
"short_name": "name",
"version": "3.6",
"manifest_version": 2,
"description": "Desc",
"permissions": [
"storage",
"http://*/",
"https://*/",
"tabs",
"activeTab",
"webNavigation",
"*://*/*",
"file://*/*"
],
"page_action": {
"default_icon": "logo.png"
},
"background": {
"scripts": ["disabled.js"]
}
}
Script that gets executed:
(hotkey-binding code too long, can be found here)
Mousetrap.bind('ctrl+m', function(e) {
window.onbeforeunload = confirmExit;function confirmExit(){alert('confirm exit is being called');return'Close page?';}
alert('Enabled');
return false;
});
Mousetrap.bind('ctrl+q', function(e) {
location.reload();
return false;
});

Auto Refresh on load page failure

I'm trying to create an extension for chrome that auto refreshes the page when the page load is failed for any reason.
my manifest.json:
{ "browser_action" : { "default_icon" : "icon.png"
},
"description" : "Making your first Google Chrome extension.",
"icons" : { "128" : "icon.png" },
"name" : "Tutorialzine Extension",
"version" : "1.0",
"permissions": [
"webRequest",
"tabs",
"<all_urls>"
],
"content_scripts": [
{
"matches": ["<all_urls>","http://*/*","https://*/*","*://*/*"],
"js": ["myscript.js"],
"run_at": "document_end"
}
]
}
myscript.js :
chrome.webRequest.onErrorOccurred.addListener(function details){
chrome.tabs.reload(details.tabId);
}
What am I doing wrong? Thanks in advance!
Content scripts don't have access to most of chrome.* APIs. It's clearly stated in the docs:
However, content scripts have some limitations. They cannot:
- Use chrome.* APIs (except for parts of chrome.extension)
You should use a background page or event page instead.
Also chrome.webRequest.onErrorOccurred.addListener(function details) is not a valid JavaScript code. function keyword shouldn't be there. I believe you copied this code from docs, but in docs this type of pseudo-JavaScript is used only to describe function definition (what types of arguments it expects, what type of values does it return etc.).