localStorage is null in chrome mobile android - javascript

I use Sentry to track the error in my website. The problem is sometimes chrome mobile for android has a null localStorage that cause all related method such as getItem or setItem will produce an error (Yeah, it's flaky). Have you ever got the problem like this before? I'd like to know the best solution for this problem.
Thanks :)

Maybe it is because this question is almost 2 years old and they've changed things but localStorage definitely works in Android Chrome with localStorage.setItem() and getItem() calls.
There is no need for the polyfill.
However, there is a problem / challenge that occurs if you've already put a page out there and you add localStorage that is related to Chrome Caching behavior. That's the problem I was having.
I had a page on the web than did some things via JavaScript. Then I added the simple localStorage calls to write and read a string value. I found that localStorage would fail.
Finally I loaded the .js file directly in my Android chrome browser and saw that the JS was the cached version of the file.
I reloaded the JS file and saw it update in Android Chrome so I went back to the page that uses the JS file and it still didn't save to localStorage.
To get it to work I had to close Android Chrome entirely (after refreshing the JS file) and finally localStorage did indeed work.
Here's a plunkr where you can point your mobile device at and save a value in localStorage to prove to yourself that it works.
http://plnkr.co/edit/dWgfh5WuMcM3InR0OaN4?p=info
Type in a screen name and press the Save button:
Then you can Stop and Run the plunkr again and you'll see that your Screen Name has been saved to localStorage and read out of localStorage to populate the top message:
I've actually tested this on various versions of Android, iOS (on an iPad) and in various desktop browsers and it works in every case.
Here's the code that calls localStorage.setItem()
function writeScreeNameToStorage(screenName){
var encodedScreenName = getEncodedValue(screenName);
localStorage.setItem("screenName", encodedScreenName);
}

Related

Firefox addon works normally as a temporary addon in the "DevTools" environment but doesn't when in a persistant profile

Background:
So. I'm currently working on a Firefox extension, and I've been testing it using web-ext, which clears the data on close. The extension has functionality across restarts, and in order to make sure it works I'd have to be able to have persistent local storage across restarts.
To test this:
I made a testing profile and ran the --firefox-profile argument. The extension runs normally with the argument, but the storage doesn't carry over since web-ext makes a temp copy of the specified profile.
This is where the --keep-profile-changes argument comes in. However, when I ran it (web-ext run --firefox-profile "[profile-directory]" --keep-profile-changes --browser-console) the extension button on the toolbar would continually disappear and reappear. Whatever was messing up the extension was also throwing lots of "sendRemoveListener on closed conduit" errors in the browser console.
Possible cause:
While looking for a solution, I found this Bugzilla report mentioning that browser.contextMenus.onClicked.addListener() (which I use in my extension) can cause that error to get thrown, but I can't seem to find a solution.
If parts of my code are needed to figure out how to fix this, let me know and I can edit the question to include it.

Chrome, even in incognito won't refresh with new changes to javascript

I'm growing frustrated with the whole mix of Spring Tool Suite, Tomcat and Chrome. I'm working on a website's back end and I'm having all sorts of troubles getting my webpage to reload properly when I make changes to the JavaScript. I've made a fix to a problem in my code and when I go to preview, the error is still there. When I inspect the JavaScript in the Chrome Dev Tools, I see that it is still loading the JavaScript before I made the change, despite me having saved the file. I've rebooted Tomcat, I've been using Incognito mode, I've been deleting my cache and yet even in incognito, Chrome won't dump the old JavaScript file for the new one.
It's getting frustrating, because I waste time with every change I make with the JavaScript trying to wrestle with Chrome and Tomcat to get my webpage to use the most recent saved version of my JavaScript. I don't know if this matters, but I'm not writing my JavaScript in STS with Tomcat and my Java code, but it is in the same folder as my project and when I open it in STS, it always has my most recent save changes anyways.
Is there any fix to this?

Only on Firefox "Loading failed for the <script> with source"

I want to integrate Marketo form with my existing website on yii framework.
My code works on all the browsers except Firefox.
Excerpt from my code:
$('#button').click(function () {
var formData = {
'Email': $('#UserInfo_email').val(),
'FirstName': $('#UserInfo_first_name').val(),
'LastName': $('#UserInfo_last_name').val(),
};
MktoForms2.loadForm('//app-ab23.marketo.com', mcId, formId, function (form) {
var myForm = MktoForms2.allForms()[0];
myForm.addHiddenFields(formData);
myForm.onSuccess(function (values, followUpUrl) {
return false;
});
myForm.submit();
});
});
I get error on Firefox only with message
Loading failed for the <script> with source “http://app-ab23.marketo.com/index.php/form/getForm?munchkinId=1111&form=1111&url=http%3A%2F%2Fblox.dev%2Fwizard%2Fmap&callback=jQuery110207175825035737486_1503656391790&_=1503656391791”.
other browsers do the job correctly
note: munchkinId and formId are changed for posting here.
I just had the same issue on an application that is loading a script with a relative path.
It appeared the script was simply blocked by Adblock Plus.
Try to disable your ad/script blocker (Adblock, uBlock Origin, Privacy Badger…) or relocate the script such that it does not match your ad blocker's rules.
If you don't have such a plugin installed, try to reproduce the issue while running Firefox in safe mode.
If you cannot reproduce it in safe mode, it means your issue is linked to one of your plugins or settings.
Otherwise, it might be a different issue. Make sure you have the same error message as in the question. Also look at the network tab of the developer tools to check if your script is listed (reload the page first if needed).
I've just had the same issue - for me Privacy Badger on Firefox was the issue - not adblocker. Posting for posterity
I noticed that in Firefox this can happen when requests are aborted (switching page or quickly refreshing page), but it is hard to reproduce the error even if I try to.
Other possible reasons: cert related issues and this one talks about blockers (as other answers stated).
Today I ran into the exact same problem while working on a progressive web app (PWA) page and deleting some cache and service worker data for that page from Firefox. The dev console reported that none of the 4 Javascript files on the page would load anymore. The problem persisted in Safe mode, so it was not an add-on issue. The same script files loaded fine from other web pages on the same website. No amount of clearing the Firefox cache or wiping web page data from Firefox would help, nor would rebooting the Windows 10 PC. Chrome all the time worked fine on the problem page. In the end I did a restore of the entire Firefox profile folder from a day-old backup, and the problem was immediately gone, so it was not a problem with my PWA app. Apparently something in Firefox got corrupted.
I had the same problem (different web app though) with the error message and it turned out to be the MIME-Type for .js files was text/x-js instead of application/javascript due to a duplicate entry in mime.types on the server that was responsible for serving the js files. It seems that this is happening if the header X-Content-Type-Options: nosniff is set, which makes Firefox (and Chrome) block the content of the js files.
As suggested above, this could possibly be an issue with your browser extensions. Disable all of your extensions including Adblock, and then try again as the code is loading fine in my browser right now (Google Chrome - latest) so it's probably an issue on your end. Also, have you tried a different browser like shudders IE if you have it? Adblock is known to conflict with domain names with track and market in them as a blanket rule. Try using private browsing mode or safe mode.
I ran into the same issue (exact error message) and after digging for a couple of hours, I found that the content header needs to be set to application/javascript instead of the application/json that I had. After changing that, it now works.
VPNs can sometimes cause this error as well, if they provide some type of auto-blocking. Disabling the VPN worked for my case.
If the src is https and the certificate has expired -- and even if you've made an exception -- firefox will still display this error message, and you can see the exact reason why if you look at the request under the network tab.
I had the same issue with firefox, when I searched for a solution I didn't find anything, but then I tried to load the script from a cdn, it worked properly,
so I think you should try loading it from a cdn link, I mean if you are trying to load a script that you havn't created.
because in my case, when tried to load a script that is mine, it worked and imported successfully, for now I don't know why, but I think there is something in the scripts from network, so just try cdn, you won't lose anything.
I wish it help you.
I ran in the same situation and the script was correctly loading in safe mode. However, disabling all the Add-ons and other Firefox security features didn't help. One thing I tried, and this was the solution in my case, was to temporary disable the cache from the developer window for this particular request. After I saw this was the cause, I wiped out the cache for that site and everything started word normally.
I've had the same problem and the culprit was the "I don't care about cookies" Firefox addon. Like another user here, I'm posting for posterity.
This could also be a simple syntax error. I had a syntax error which threw on FF but not Chrome as follows:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
defer
</script>
I've just run into this issue while building Facebook Login into my ASP.NET project.
It turned out to be an extension called Facebook Container, which blocks the Facebook SDK script unless you add an exception for the site in question.
Once I added the exception it all worked fine.
Ran into the same problem today. It turned out that there was no storage space left on the VM the site was running on and therefore requests weren't completely handled anymore.
After cleaning things up (notably Docker-related stuff), everything works fine again.
For me it wasn't AdBlock, but actually a wrong relative path. Wrong error message I guess. I was able to see this in the server logs.
For me it was NoScript extension which was installed by default by my company. I configured localhost to be safe, then it worked.
For me (Next.js project static export) it was due to cache. I did a hard refresh Ctrl + F5 and everything started working fine.

SoundJS: Firefox is not able to play a mp3

I am currently working on a website that includes a musicplayer made with SoundJS.
I, myself, am using Google Chrome to test and debug my website, and it worked like a charm, but when I recently tested it in FireFox, I noticed this strange error.
When I hit the play button and the sound is being registered I get this error:
The buffer passed to decodeAudioData contains an unknown content type
The code I use in my javascript file to create the soundInstance:
'response' is a string containing the location of the .mp3 file (this all works perfectly in Chrome).
createjs.Sound.registerSound('uploads/songs/'+response,'song');
When I test this same piece of code with an 'ogg' file it works perfectly in FireFox.
I also heard from some people that it doesn't work in Safari too, but unfortunatly I am a windows user.
If you want to test it for yourself:
www.playmesome.be . Just hit the play button and it will keep on loading infinitely because of this error.
Thanks for reading!
there is a known issue with Firefox on windows that does not load all mp3 files properly, and therefore it is recommended that you load another supported file type first (such as ogg).
Hope that helps.

How to check if the OS handles certain URL protocols? (cross-browser)

I have set my Cocoa app to be an URL handler for com_example_myapp: protocol (using this great tutorial). So, the link in Safari <a href="com_example_myapp://link"> now opens my app. Cool.
But before I give the user the link in the web browser, how can I determine whether the client's OS is capable to handle it? How to check this via JS (PHP, ...)?
I have found a lot of solutions (mostly for Mobile Safari) but cannot find anything cross-browser compatible.
From what I know, Chrome doesn't support this. You can try using a try/catch but it won't return anything. You can use your other references and put a specific call in their for Safari.
Lastly, I haven't tested it, but you can bind something to the window to see if it blurs.
$(window).blur(function() {
//code to see if it blurred on a setTimeout
}
Then record the date of creating it and see if it's within 1 second so when they come back you can destroy the timer if it's still there.
Just ideas though...

Categories

Resources