-
-
Notifications
You must be signed in to change notification settings - Fork 129
Fix bugs related to strict privacy settings in browsers #1166
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,15 @@ export type PrivacyAsyncStorageOption = { | |||||
|
|
||||||
| type KeyValueDatabase = IDBPDatabase<{ [key: string]: string }>; | ||||||
|
|
||||||
| const errorFilter = (e: Error) => | ||||||
| // These migh be caused if IndexedDB is disabled in Firefox | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| e.name === 'InvalidStateError' || | ||||||
| e.name === 'SecurityError' || | ||||||
| // We couldn’t identify the cause for this error, but it seems to be caused by problem in the browser, so there is | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| // no need to tell the user about it (we should fail gracefully anyway). | ||||||
| // See also: https://github.com/datenanfragen/website/issues/1014 | ||||||
| e.message === 'Internal Error'; | ||||||
|
|
||||||
| export class PrivacyAsyncStorage { | ||||||
| #db?: typeof localStorage | KeyValueDatabase; | ||||||
| #options: PrivacyAsyncStorageOption; | ||||||
|
|
@@ -49,7 +58,7 @@ export class PrivacyAsyncStorage { | |||||
| }, | ||||||
| }) | ||||||
| .catch((e: DOMException) => { | ||||||
| if (e.name === 'InvalidStateError') { | ||||||
| if (errorFilter(e)) { | ||||||
| // Database is not writable, we are probably in Firefox' private browsing mode | ||||||
| this.#storageType = 'localStorage'; | ||||||
| this.#db = localStorage; | ||||||
|
|
@@ -144,20 +153,29 @@ export class PrivacyAsyncStorage { | |||||
| } | ||||||
|
|
||||||
| static async doesStoreExist(name: string, storeName: string) { | ||||||
| const db: IDBPDatabase | void = await openDB(name, undefined, { blocking: () => db?.close() }).catch((e) => { | ||||||
| if (e.name === 'InvalidStateError' && e.name === 'VersionError') { | ||||||
| db?.close(); | ||||||
| try { | ||||||
| const db: IDBPDatabase | void = await openDB(name, undefined, { blocking: () => db?.close() }).catch( | ||||||
| (e) => { | ||||||
| if (errorFilter(e) || e.name === 'VersionError') { | ||||||
| db?.close(); | ||||||
| return; | ||||||
| } | ||||||
| rethrow(e, 'Error in doesStoreExist', { name, storeName, db }, t('indexeddb-error', 'error-msg')); | ||||||
| } | ||||||
| ); | ||||||
|
|
||||||
| if (db) { | ||||||
| const result = db.objectStoreNames.contains(storeName); | ||||||
| db.close(); | ||||||
| return result; | ||||||
| } | ||||||
| } catch (e) { | ||||||
| if (e instanceof Error && errorFilter(e)) { | ||||||
| return; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason we're returning |
||||||
| } | ||||||
| rethrow(e, 'Error in doesStoreExist', { name, storeName, db }, t('indexeddb-error', 'error-msg')); | ||||||
| }); | ||||||
|
|
||||||
| if (db) { | ||||||
| const result = db.objectStoreNames.contains(storeName); | ||||||
| db.close(); | ||||||
| return result; | ||||||
| } | ||||||
| return ( | ||||||
| localStorage && | ||||||
| typeof Object.keys(localStorage).find((key) => new RegExp(`^${name}/${storeName}/`).test(key)) === 'string' | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ const PrivacyControl = (props: PrivacyControlProps) => ( | |||||||||||||||||||||||||
| checked={Privacy.isAllowed(PRIVACY_ACTIONS[props.privacyAction])} | ||||||||||||||||||||||||||
| type="checkbox" | ||||||||||||||||||||||||||
| className="form-element" | ||||||||||||||||||||||||||
| disabled={!navigator.cookieEnabled} | ||||||||||||||||||||||||||
| onChange={(event) => { | ||||||||||||||||||||||||||
| Privacy.setAllowed(PRIVACY_ACTIONS[props.privacyAction], event.currentTarget.checked); | ||||||||||||||||||||||||||
| flash( | ||||||||||||||||||||||||||
|
|
@@ -91,6 +92,14 @@ const PrivacyControls = () => { | |||||||||||||||||||||||||
| <ClearMyRequestsModal /> | ||||||||||||||||||||||||||
| <MarkupText id="explanation" /> | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| {!navigator.cookieEnabled ? ( | ||||||||||||||||||||||||||
| <div className="box box-info"> | ||||||||||||||||||||||||||
| <Text id="explanation-cookies-disabled" /> | ||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||
| <></> | ||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||
|
Comment on lines
+95
to
+101
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| <table> | ||||||||||||||||||||||||||
| {Object.keys(PRIVACY_ACTIONS).map((action) => ( | ||||||||||||||||||||||||||
| <PrivacyControl | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a TODO comment?