Skip to content

Instantly share code, notes, and snippets.

@ben1one
Last active August 7, 2024 07:29
Show Gist options
  • Save ben1one/6c1172cc4d84c183f8f03a13dbbe4b60 to your computer and use it in GitHub Desktop.
Save ben1one/6c1172cc4d84c183f8f03a13dbbe4b60 to your computer and use it in GitHub Desktop.
// 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