chrome.cookies.get showing either undefined or throwing error - javascript

chrome.cookies.get({url:"http://www.dahotre.com", name:"userid"}, function(){}) shows undefined in the console.
If I skip the optional empty function(), it throws an error.
chrome.cookies.get({url:"http://www.dahotre.com", name:"userid"}) shows Uncaught Error: Parameter 2 is required.
And if I use function(Cookie c){} as the second param, it throws SyntaxError: Unexpected identifier
Following is the permissions line from my manifest.json:
"permissions": [ "cookies", "http://www.dahotre.com/"],
When I inspect the cookies in my browser, I can most certainly find a cookie from the site www.dahotre.com with a name=userid and a integer content.
How to access this cookie in a chrome extension?

Try:
chrome.cookies.get({url:"http://www.dahotre.com", name:"userid"}, function(cookies){
console.log(cookies);
});
Your function(Cookie c){} was a nice try, but JavaScript is dynamically typed language and those verbose types are used only for documentantion purpose.

Related

Uncaught (in promise) TypeError: localStorage.setItem is not a function

I want to create a project with localstorage, but when I save it with setItem error show up like this:
Uncaught (in promise) TypeError: localStorage.setItem is not a
function
This is my code:
var dataPerson = {
name: "Jhon",
old: 20,
family: "Doe",
};
console.log(dataPerson);
if (typeof(Storage) !== "undefined") {
// Store
localStorage.setItem("data", JSON.stringify(dataPerson));
} else {
alert("Sorry, your browser does not support Web Storage...");
}
I use jQuery v3.4.1, Thank you
Can you try invoking localStorage from the window object...
window.localStorage.setItem("data", JSON.stringify(dataPerson));
This worked for me.
Check your code again if you've redefined the localStorage on somewhere else.
The code is completely working.
https://stackblitz.com/edit/js-jpzvta?embed=1&file=index.js
from https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage:
Exceptions
SecurityError
The request violates a policy decision, or the origin is not a valid scheme/host/port tuple (this can happen if the origin uses the
file: or data: scheme, for example). For example, the user may have
their browser configured to deny permission to persist data for the
specified origin.
so you should envelope your code with a try-catch, that will solve your
Uncaught (in promise) TypeError: localStorage.setItem is not a
function
in https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API you have an example of it, and given your particular exception, I'd start by
Feature-detecting localStorage
To be able to use localStorage, we should first verify that it is
supported and available in the current browsing session.

when trying to .click() on element i get Error: Permission denied to access property 'length'

in my FF extension i use the addon sdk. The content script i have written works just fine.
I can find the proper div element and get the .html() output with jQuery out of it
The problem is when i try to run .click() on it i get this error:
Error: Permission denied to access property 'length'
i am running FF 32.0.3 and sdk 1.16
this the line of code that breaks:$("#sampleid").click();
and this is the error that i get:System JS : ERROR resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///c:/users/andriy/appdata/local/temp/tmpthua0e.mozrunner/extensions/jid1-LetHopSfdqAf7A#jetpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/loader/sandbox.js -> resource://jid1-lethopsfdqaf7a-at-jetpack/my_addon/data/scripts/jquery.js:3 - Error: Permission denied to access property 'length'
Edit: this is my page mod:pageMod.PageMod({
include: "*",
contentStyleFile: [self.data.url("css/style.css"), self.data.url("css/dropdown.css")],
contentScriptFile: [self.data.url("scripts/jquery.js"), self.data.url("scripts/dropdown.js"), self.data.url("scripts/pageParser.js")],
contentScriptWhen: "end",
onAttach: function(worker){}
});
and pageParser.js contains the .click() code
that was all i wrote because this was just a test extension to understand why it wont work
Edit2: this is literally all i have in pageParser.js
function click1(){
console.log("123456789");
//alert($('#sampleid').html());
$('#sampleid').click();
}
click1();
Edit 3: Im not sure but i think this might have something to do with this. Unfortunately i cant seem to modify the examples to help me
https://blog.mozilla.org/addons/2014/04/10/changes-to-unsafewindow-for-the-add-on-sdk/
Edit 4: It seems this gentleman had the same issue as me:
https://groups.google.com/forum/#!topic/greasemonkey-users/SXfpyvcQofQ
i also stopped using jQuery and now it works
Edit 5: $("div:contains('my sample text')").click();

Why is a button submitting a form even when I set the type to button (rather than submit)?

Click on "Add another start and end time." Notice that the "Remove this segments." buttons are behaving as if their types are not being changed. I ran this through JSLint without any issues and I'm not getting errors in the console. Using the web developer tools in Chrome, it looks like it's type attribute isn't getting set. I can't figure out what's going on.
http://jsfiddle.net/gtr053/xtGPR/
Firefox says:
Error: uncaught exception: [Exception... "Index or size is negative or greater than the allowed amount" code: "1" nsresult: "0x80530001 (NS_ERROR_DOM_INDEX_SIZE_ERR)" location: "http://fiddle.jshell.net/gtr053/xtGPR/show/ Line: 39"]
Line 39 is:
document.getElementById('start_end_times').getElementsByTagName('tbody')[0].deleteRow(index);
So presumably index is wrong.

Uncaught TypeError - JavaScript

I get that error :
Uncaught TypeError: Cannot set property 'onclick' of null
initJavaScript
File:
http://www.radiomrs.pl/wp-content/plugins/pierres-wordspew/ajax_shout.js
91 line
Why it's something like that?
On site http://radiomrs.pl shoutbox work nice.
You should trust your browser... ;)
Go to line 91 of ajax_shout.js and you'll find:
document.getElementById('submitchat').onclick = sendComment;
document.getElementById('submitchat') is null, that is there's no such element in your DOM, or the element has not been loaded yet when the script tries to access it.

Javascript error in IE

I have a page which is showing a javascript error in IE, stating which line the error is on, but the there are so many linked files I have no idea which line of code it is referring to.
Is there a way to find out which line / linked file it is relating to?? I'm sure I could fix the problem if I knew where it was.
Here is the error message from IE...
Message: 'null' is null or not an object
Line: 2231
Char: 5
Code: 0
URI: http://www.hpbtenancies.co.uk/location/JF/default.aspx
It happens on the line the error reports.. 2231 on default.aspx
dd.onchange = function(){ link.href = hrefOrig + dd.value;
The detailed error is
dd is null
Use Firefox which has better reporting and also use FireBug for even more flexibility in debugging javascript..
IE 8+ also has improved javascript debugging tools. In the console you will see
SCRIPT5007: Unable to set value of the property 'onchange': object is null or undefined
default.aspx, line 2231 character 5
Right-click on the page with the error, click 'View source', scroll down until you reach line 2231 - that's where your error is.

Categories

Resources