Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page crash iOS Safari in Private mode: infinite loop SessionStorage read warning #144

Closed
bgever opened this issue Mar 14, 2016 · 5 comments
Assignees
Labels
Milestone

Comments

@bgever
Copy link

bgever commented Mar 14, 2016

As of a few weeks ago, user reported issue with iOS Safari in Private mode. Normal mode works fine.

When loading the page with the AI script, the browser reports eventually in a message bar:
A problem occured with this webpage so it was reloaded.
and the page content has only the message:
A problem repeatedly occurred on "<URL>"..

Reproduced with Browserstack real browser on various devices and on my own iPhone.

The console log has repeatedly this message (up to 6400 times):

ai.0.js:1 AI (Internal): NONUSRACT_BrowserCannotWriteSessionStorage message:"Browser failed write to session storage. " props:"{exception:[object DOMException]{\code\:22,\name\:\QuotaExceededError\,\message\:\QuotaExceededError: DOM Exception 22\,\line\:1,\column\:16686,\sourceURL\:\https://az416426.vo.msecnd.net/scripts/a/ai.0.js\}}"

When Safari is in Private mode it doesn't allow to read session storage.

The AI code has a try/catch around that, but somehow the attempt is repeated.

ai safari private infinite loop

@jensenthomas
Copy link

I also have the issue for my web site.

For Safari in private browsing the browser hands out the window.localStorage objet but throws an exception when using the SetItem member.

The problem is in Util.ts. The _getStorageObject and _getSessionStorageObject functions return the storage object but when the write functions use the storage object it throws an exception causing the write functions to return false. This causes the caller loop.

The _getStorage*Object functions should use a pattern where they validate the storage object by performing a test write operation before handing out the object. This is a common pattern - e.g. see https://mathiasbynens.be/notes/localstorage-pattern.

bgever added a commit to bgever/ApplicationInsights-JS that referenced this issue Mar 14, 2016
Private browsing in iOS Safari does provide a sessionStorage object, but
throws an error when getting or setting an item. By getting the empty
string key, it would cause an error to throw, which is caught by the
existing try/catch that detects whether session storage is available.
Fixes microsoft#144
@bgever
Copy link
Author

bgever commented Mar 14, 2016

Hope the AI team can review the PR which should fix this issue. I can't run the unit tests locally, the PS script opens an HTML page with empty unit tests. I can test the results via Browserstack.

@bgever
Copy link
Author

bgever commented Mar 14, 2016

@tsj0603 thanks for explaining that. While you were typing that out, I was making the PR, teamwork! 😄

@AlexBulankou AlexBulankou self-assigned this Mar 14, 2016
@AlexBulankou AlexBulankou added this to the 98 milestone Mar 14, 2016
@bgever
Copy link
Author

bgever commented Mar 15, 2016

As confirmed in PR #146, the issue has been fixed and CDN has been updated. Again, thanks a lot for the quick fix, @AlexBulankou. 😄

@bgever bgever closed this as completed Mar 15, 2016
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants