Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function save(namespaces) {
if (null == namespaces) {
exports.storage.removeItem('debug');
} else {
exports.storage.debug = namespaces;
exports.storage.setItem('debug', namespaces);
}
} catch(e) {}
}
Expand All @@ -144,7 +144,7 @@ function save(namespaces) {
function load() {
var r;
try {
r = exports.storage.debug;
r = exports.storage.getItem('debug');
} catch(e) {}

// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
Expand All @@ -168,6 +168,11 @@ function load() {

function localstorage() {
try {
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
if (typeof window === 'undefined' && typeof navigationDocument !== 'undefined') {
return localStorage;
}

return window.localStorage;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could just change this line to localStorage and have no if check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would definitely work for the TVMLKit scenario, does that work for the general browser scenario as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window is the global object in the web browser, so I can't really think of a scenario where it would be a problem. Only one way to find out though, haha.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I concur. That would work fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll make that change

} catch (e) {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This try/catch is now unnecessary, isn't it? cc @TooTallNate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old versions of IE don't support local storage, so this would throw when attempting to access it.

}
Expand Down