File tree 4 files changed +28
-6
lines changed
devtools/src/devtools/lib
4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change 1
1
import Bridge from 'crx-bridge' ;
2
2
3
- const localSettings = JSON . parse ( localStorage . getItem ( 'playground_settings' ) ) ;
3
+ const localSettings = navigator . cookieEnabled
4
+ ? JSON . parse ( localStorage . getItem ( 'playground_settings' ) )
5
+ : { } ;
6
+
4
7
let _settings = Object . assign (
5
8
{
6
9
testIdAttribute : 'data-testid' ,
@@ -17,5 +20,7 @@ export function getSettings() {
17
20
export function setSettings ( settings ) {
18
21
Object . assign ( _settings , settings ) ;
19
22
Bridge . sendMessage ( 'SET_SETTINGS' , _settings , 'content-script' ) ;
20
- localStorage . setItem ( 'playground_settings' , JSON . stringify ( _settings ) ) ;
23
+ if ( navigator . cookieEnabled ) {
24
+ localStorage . setItem ( 'playground_settings' , JSON . stringify ( _settings ) ) ;
25
+ }
21
26
}
Original file line number Diff line number Diff line change @@ -22,9 +22,18 @@ function Settings({ settings, dispatch }) {
22
22
23
23
const showBehavior = typeof settings . autoRun !== 'undefined' ;
24
24
const showTestingLibrary = typeof settings . testIdAttribute !== 'undefined' ;
25
+ const isCookieEanbled = navigator . cookieEnabled ;
25
26
26
27
return (
27
- < div className = "settings text-sm pb-2" >
28
+ < div className = "settings text-sm pb-2 " >
29
+ { ! isCookieEanbled && (
30
+ < p
31
+ className = "text-sm font-bold text-orange-600 border border-orange-600 px-3 py-1"
32
+ role = "alert"
33
+ >
34
+ Cookie are not enabled, settings will not be saved.
35
+ </ p >
36
+ ) }
28
37
< form onChange = { handleChange } onSubmit = { ( e ) => e . preventDefault ( ) } >
29
38
{ showBehavior && (
30
39
< div >
Original file line number Diff line number Diff line change @@ -207,7 +207,12 @@ const effectMap = {
207
207
} ,
208
208
209
209
SAVE_SETTINGS : ( state ) => {
210
- localStorage . setItem ( 'playground_settings' , JSON . stringify ( state . settings ) ) ;
210
+ if ( navigator . cookieEnabled ) {
211
+ localStorage . setItem (
212
+ 'playground_settings' ,
213
+ JSON . stringify ( state . settings ) ,
214
+ ) ;
215
+ }
211
216
} ,
212
217
213
218
APPLY_SETTINGS : ( state , effect , dispatch ) => {
@@ -259,7 +264,9 @@ const effectMap = {
259
264
} ;
260
265
261
266
function getInitialState ( props ) {
262
- const localSettings = JSON . parse ( localStorage . getItem ( 'playground_settings' ) ) ;
267
+ const localSettings = navigator . cookieEnabled
268
+ ? JSON . parse ( localStorage . getItem ( 'playground_settings' ) )
269
+ : { } ;
263
270
264
271
const state = {
265
272
...props ,
Original file line number Diff line number Diff line change @@ -71,7 +71,8 @@ function renderDiff(diff) {
71
71
// when debug is `undefined` and can be enabled by setting it to either `true`
72
72
// or `diff`. On develop, it's enabled when `undefined`, and can be disabled
73
73
// by setting it to `false`.
74
- const debug = localStorage . getItem ( 'debug' ) ;
74
+ const debug = navigator . cookieEnabled ? localStorage . getItem ( 'debug' ) : 'false' ;
75
+
75
76
const logLevel = debug === 'false' ? false : debug === 'true' ? true : debug ;
76
77
const isLoggingEnabled =
77
78
process . env . NODE_ENV === 'development' ? logLevel !== false : ! ! logLevel ;
You can’t perform that action at this time.
0 commit comments