Feat: Web loader
This commit is contained in:
24
Loader/scripts/storage.js
Normal file
24
Loader/scripts/storage.js
Normal file
@@ -0,0 +1,24 @@
|
||||
// Path: Loader/scripts/storage.js
|
||||
|
||||
import { LOADER_INTENT_STORAGE_KEY, LOADER_META_STORAGE_KEY, LOADER_SEEN_COOKIE_MAX_AGE_SECONDS, LOADER_SEEN_COOKIE_NAME } from "./config.js";
|
||||
import { collectClientHints } from "./hints.js";
|
||||
|
||||
export const persistLoaderState = (intent) => {
|
||||
const payload = {
|
||||
intent,
|
||||
hints: collectClientHints(),
|
||||
};
|
||||
|
||||
try {
|
||||
window.sessionStorage.setItem(LOADER_INTENT_STORAGE_KEY, intent);
|
||||
window.sessionStorage.setItem(LOADER_META_STORAGE_KEY, JSON.stringify(payload));
|
||||
} catch (error) {
|
||||
console.warn("[Loader] Unable to persist bootstrap state.", error);
|
||||
}
|
||||
|
||||
return payload;
|
||||
};
|
||||
|
||||
export const markLoaderSeen = () => {
|
||||
document.cookie = `${LOADER_SEEN_COOKIE_NAME}=1; Path=/; Max-Age=${LOADER_SEEN_COOKIE_MAX_AGE_SECONDS}; SameSite=Lax`;
|
||||
};
|
||||
Reference in New Issue
Block a user