manifest:
{
"name": "jQuery DOM",
"version": "1",
"manifest_version": 2,
"description": "Manipulate the DOM when the page is done loading",
"background_page": "background.html",
"browser_action": {
"name": "Manipulate DOM",
"icons": ["icon.png"],
"default_icon": "icon.png"
},
"content_scripts": [ {
"js": [ "jquery.min.js", "background.js" ],
"matches": [ "http://*/*", "https://*/*"]
}]
}
background.js:
var time = new Date().getTime();
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST","https://api.twitter.com/oauth/request_token",true);
xmlhttp.setRequestHeader("oauth_callback","http://127.0.0.1:81");
xmlhttp.setRequestHeader("oauth_consumer_key","1xFLKhdwNEz3xfXXXXXXXXXXX");
xmlhttp.setRequestHeader("oauth_nonce",time);
xmlhttp.setRequestHeader("oauth_signature_method","HMAC-SHA1");
xmlhttp.setRequestHeader("oauth_timestamp",time);
xmlhttp.setRequestHeader("oauth_version","1.0");
xmlhttp.send();
request header:
:host:api.twitter.com :method:POST :path:/oauth/request_token
:scheme:https :version:HTTP/1.1 accept:/ accept-encoding:gzip,
deflate accept-language:zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
content-length:0 cookie:pid="v3:14..........
oauth_callback:http://127.0.0.1:81
oauth_consumer_key:1xFLKhdwNEz3xfXXXXXXXXXXX oauth_nonce:1424942962828
oauth_signature_method:HMAC-SHA1 oauth_timestamp:1424942962828
oauth_version:1.0 origin:http://127.0.0.1:81
referer:http://127.0.0.1:81/ user-agent:Mozilla/5.0 (Windows NT 6.1)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115
Safari/537.36
Any solution??? or I just fill in the parameter with wrong value
or wrong parameter
or wrong request method
or chrome extension issues???
My suggestion would be to add permissions for certain website in your manifest.json. This worked for me for a similar issue.
For example:
"permissions": [
["<all_urls>"]
],
Related
I have followed a few tutorials out there:
https://developer.chrome.com/apps/app_identity
https://github.com/GoogleDeveloperExperts/chrome-extension-google-apis
https://mashe.hawksey.info/2017/05/using-the-google-apps-script-execution-api-in-chrome-extensions/
to get my chrome extension to authenticate with a Google API project but this code:
chrome.identity.getAuthToken({ 'interactive': false }, function (token) {
// Catch chrome error if user is not authorized.
if (chrome.runtime.lastError) {
$("#__sample_support_logarea").text(chrome.runtime.lastError.message);
console.log('No token aquired');
console.log(chrome.runtime.lastError.message);
sampleSupport.log('No token aquired');
sampleSupport.log(chrome.runtime.lastError.message);
} else {
console.log('Token acquired');
console.log(token);
}
});
always returns:
OAuth2 request failed: Invalid credentials (credentials rejected by client).
Here is my manifest.json:
{
"manifest_version": 2,
"name": "Shopify Partners",
"description": "Automate Proposal Creation",
"version": "1.0",
"background": {
"scripts": [
"background.js"
]
},
"content_scripts": [
{
"js": [ "jquery.min.js", "main.js" ],
"matches": [ "http://*/*", "https://*/*" ]
}
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab",
"identity",
"https://accounts.google.com/*",
"https://www.googleapis.com/*"
],
"oauth2": {
"client_id": "..sr1t2ass4f9a0.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/spreadsheets"
]
},
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp8Cj7TI9toe9nK0Pw8FFk1hOlSCPUwJ/GUmWUgzyO3XBP2KoIFv+ISpOoPO++itYsDaXBgZzjk/EUeFMPUWbmuL6+lfs6orq39mMzQKLZEMV05bRaVVsj7gMtBGrsuOJm83Ugw+2tUVszH/yCzMFYNGqJe+ZaEPyUDVqeOfbZoo+JDleDveu0j+HTKDa6wVdDxndT+N86IEoPKCWfXdzMZ6+22ZTSPKYIvQbaHalqEQ9YAc80eHaL0eQNq/+aEv3oNWm2rbB8fy79koQKkZBuWJqgWmznWe6NzPkEpsiE+ilaUCKzWzFDFpiIC0A5Eq3KpWQdnQYDF1A2gmTh9vgkQIDAQAB",
"content_security_policy": "script-src 'self' https://apis.google.com https://ajax.googleapis.com; object-src 'self'"
}
Please note that I have omitted the complete client id here for security reasons.
The only thing that I suspect might be the reason for this is that I am running an unpacked extension in chrome dev mode which id is something like: gcnonhfkghlloailceiddfmlmdeajlkl
And in the Api Console when creating the credentials for the client I have specified the same:
Therefore I suspect that being an unpackaged extension might be comprising it. But publishing an extension in the Chrome store is a long process and certainly is not what is expected of such a simple task.
I think your extension id has changed. The same thing happened to me.
To fix this, I again created google OAuth 2.0 Client ID and it has been fixed.
I have page https://somepage in internet. Here is part of it's code from chrome code:
..............
<div class="wr">
<div class="auth_username">tesеDom#mail.com</div>
<div class="auth_stars">
<i class="fa fa-star-o fa-fw">
...........................
I have seen many answers and examples, but my code still not working. Seems I am missing something. My manifest:
{
"manifest_version": 2,
"name": "Bot_copy",
"version": "1.0",
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"icons": {
"48": "48x48.png",
"128": "128x128.png"
},
"content_scripts": [{
"matches": [ "https://mypage.my" ],
"js": ["helloWorld.js"]
}],
"permissions": [
"activeTab",
"alarms",
"clipboardRead",
"clipboardWrite",
"bookmarks",
"contextMenus",
"contentSettings",
"downloads",
"history",
"nativeMessaging",
"browsingData",
"proxy",
"webRequest",
"webRequestBlocking",
"cookies",
"tabs",
"webNavigation",
"storage",
"tabCapture",
"notifications",
"http://*/",
"https://*/",
"<all_urls>",
"unlimitedStorage",
"debugger"
],
"browser_action": {
"default_title": "Open"
},
"background": {
"scripts": ["background.js"]
}
}
content script
window.onload = function() {
sendMessage();
}
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
sendResponse({
response: "Message received"
});
});
//Send message to background page
function sendMessage() {
//Construct & send message
chrome.runtime.sendMessage({
whattodo:"get_authname"
}, function(response) {
});
}
background
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var name = document.getElementsByClassName('auth_username').value;
alert(name);
sendResponse({
response: "Message received"
});
}
);
I received alert "undefined".
Have no idea. Really strange there are no properly documentation I don't understand object document.
Seems I miss how to use documentc object. I tried also document.getElementsByTagName('auth_username'), but it also not working. Which way is correct?
You can not access DOM from background script. You can access DOM from content script only. so try to place following code:
var name = document.getElementsByClassName('auth_username').value;
alert(name);
in contentscript and it works.
I am writing a webextension for Chrome and Firefox that uses the Page Action model. In the manifest.json I provide match rules for the URL so that it only shows on a specific URL. This works fine in Firefox, but the icon stays inactive all the time in Chrome. Here's my Chrome manifest.json, which is the same as the Firefox one but without the firefox specific aplications property. The url of the webpage when loaded is exactly the same in Chrome as in Firefox.
{
"manifest_version": 2,
"name": "MyExtension",
"version": "0.1.1",
"description": "A description",
"permissions": [
"activeTab",
"storage"
],
"page_action": {
"default_title": "MyExtension",
"default_popup": "popup.html",
"default_icon": {
"16": "images/icon16.png",
"32": "images/icon32.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"show_matches": ["https://example.com/#*"],
"hide_matches": ["https://example.com/#*/*"]
}
}
Is it possible to open your chrome extension on a new tab? I would like to be able to create a chrome browser that has same approach like the bookmark manager. See figure 1.0 below
I would like my application to like/have an address
chrome://personalize_calendar_stuff
is that possible? I can't find on the manifest references.
Thanks to #wOxxOm for giving me an idea.
I added this script on my index.js
chrome.browserAction.onClicked.addListener(function(){
chrome.tabs.create({url: "main.html"});
})
and on below is an example of manifest file I used.
{
"name" : "Testing Chrome",
"version": "1.0",
"background":
{
"scripts": ["index.js"]
},
"description": "A testing example app",
"permissions":[
"tabs",
],
"content_security_policy": "script-src 'self'; object-src 'self'",
"browser_action": {
"default_title": "testing chtome",
"default_icon": "icon.png"
},
"manifest_version": 2
}
XMLHttpRequest cannot load http://localhost:4567/save. Origin chrome-extension://cbemaelkkmebiohhjgmlclegalijdbbh is not allowed by Access-Control-Allow-Origin.
Even thought I'm getting this error the extension seems to be calling the URL. The message passing from contentscript.js to background.html took me a few minutes to wire up, but seems ok. I'm confused.
Here is my manifest.
{
"name": "FirstExt",
"version": "1.0",
"description": "My First Extension",
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"content_scripts": [
{
"matches": ["http://*"],
"js": ["jquery.min.js", "contentscript.js"]
}
],
"background_page": "background.html",
"permissions": [ "http://*",
"http://localhost:4567/*" ]
}
Try changing http://* to http://*/ (and removing the localhost entry).
If you're trying to access a https page, you will need that too.
Replace "http://*" with "<all_urls>".