Last active
August 7, 2024 07:29
-
-
Save ben1one/6c1172cc4d84c183f8f03a13dbbe4b60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Collect cookies information | |
const cookies = document.cookie.split(';').map(cookie => { | |
const [name, value] = cookie.trim().split('='); | |
return { | |
name, | |
value, | |
domain: document.domain, | |
path: '/', | |
expires: -1, | |
httpOnly: false, | |
secure: false, | |
sameSite: 'Lax' | |
}; | |
}); | |
// Collect localStorage information | |
const localStorageItems = Object.entries(localStorage).map(([name, value]) => { | |
return { name, value }; | |
}); | |
// Create the storage state object | |
const storageState = { | |
cookies, | |
origins: [ | |
{ | |
origin: window.location.origin, | |
localStorage: localStorageItems | |
} | |
] | |
}; | |
// Output the storage state in Playwright format | |
console.log(JSON.stringify(storageState, null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment