1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["3255"],{52965(e,s,r){r.r(s),r.d(s,{metadata:()=>t,default:()=>h,frontMatter:()=>i,contentTitle:()=>l,toc:()=>c,assets:()=>o});var t=JSON.parse('{"id":"api/class-webstorage","title":"WebStorage","description":"WebStorage exposes the page\'s localStorage or sessionStorage for the current origin via an async, browser-consistent API.","source":"@site/docs/api/class-webstorage.mdx","sourceDirName":"api","slug":"/api/class-webstorage","permalink":"/docs/next/api/class-webstorage","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"class-webstorage","title":"WebStorage"},"sidebar":"api","previous":{"title":"WebSocketRoute","permalink":"/docs/next/api/class-websocketroute"},"next":{"title":"Worker","permalink":"/docs/next/api/class-worker"}}'),n=r(74848),a=r(28453);r(13554),r(41647),r(83137);let i={id:"class-webstorage",title:"WebStorage"},l,o={},c=[{value:"Methods",id:"methods",level:2},{value:"clear",id:"web-storage-clear",level:3},{value:"getItem",id:"web-storage-get-item",level:3},{value:"items",id:"web-storage-items",level:3},{value:"removeItem",id:"web-storage-remove-item",level:3},{value:"setItem",id:"web-storage-set-item",level:3}];function d(e){let s={a:"a",code:"code",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(s.p,{children:["WebStorage exposes the page's ",(0,n.jsx)(s.code,{children:"localStorage"})," or ",(0,n.jsx)(s.code,{children:"sessionStorage"})," for the current origin via an async, ",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/API/Storage",children:"browser-consistent"})," API."]}),"\n",(0,n.jsxs)(s.p,{children:["Instances are accessed through ",(0,n.jsx)(s.a,{href:"/docs/next/api/class-page#page-local-storage",children:"page.localStorage"})," and ",(0,n.jsx)(s.a,{href:"/docs/next/api/class-page#page-session-storage",children:"page.sessionStorage"}),"."]}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",children:"await page.goto('https://example.com');\nawait page.localStorage.setItem('token', 'abc');\nconst token = await page.localStorage.getItem('token');\nconst all = await page.localStorage.items();\nawait page.localStorage.removeItem('token');\nawait page.localStorage.clear();\n"})}),"\n",(0,n.jsx)(s.hr,{}),"\n",(0,n.jsx)(s.h2,{id:"methods",children:"Methods"}),"\n",(0,n.jsx)(s.h3,{id:"web-storage-clear",children:"clear"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.61"}),"\n",(0,n.jsx)("x-search",{children:"webStorage.clear"}),"\n",(0,n.jsx)(s.p,{children:"Removes all items from the storage."}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Usage"})}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",children:"await webStorage.clear();\n"})}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Returns"})}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,n.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"web-storage-clear-return"}),(0,n.jsx)("a",{href:"#web-storage-clear-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,n.jsx)(s.hr,{}),"\n",(0,n.jsx)(s.h3,{id:"web-storage-get-item",children:"getItem"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.61"}),"\n",(0,n.jsx)("x-search",{children:"webStorage.getItem"}),"\n",(0,n.jsxs)(s.p,{children:["Returns the value for the given ",(0,n.jsx)(s.a,{href:"/docs/next/api/class-webstorage#web-storage-get-item-option-name",children:"name"})," if present."]}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Usage"})}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",children:"await webStorage.getItem(name);\n"})}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Arguments"})}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:["\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"name"})," ",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,n.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"web-storage-get-item-option-name"}),(0,n.jsx)("a",{href:"#web-storage-get-item-option-name",class:"list-anchor",children:"#"})]}),"\n",(0,n.jsx)(s.p,{children:"Name of the item to retrieve."}),"\n"]}),"\n"]}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Returns"})}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null",title:"null",children:"null"})," | ",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),">",(0,n.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"web-storage-get-item-return"}),(0,n.jsx)("a",{href:"#web-storage-get-item-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,n.jsx)(s.hr,{}),"\n",(0,n.jsx)(s.h3,{id:"web-storage-items",children:"items"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.61"}),"\n",(0,n.jsx)("x-search",{children:"webStorage.items"}),"\n",(0,n.jsx)(s.p,{children:"Returns all items in the storage as name/value pairs."}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Usage"})}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",children:"await webStorage.items();\n"})}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Returns"})}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array",title:"Array",children:"Array"}),"<",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),">>",(0,n.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"web-storage-items-return"}),(0,n.jsx)("a",{href:"#web-storage-items-return",class:"list-anchor",children:"#"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:["\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"name"})," ",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})]}),"\n"]}),"\n",(0,n.jsxs)(s.li,{children:["\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"value"})," ",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,n.jsx)(s.hr,{}),"\n",(0,n.jsx)(s.h3,{id:"web-storage-remove-item",children:"removeItem"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.61"}),"\n",(0,n.jsx)("x-search",{children:"webStorage.removeItem"}),"\n",(0,n.jsxs)(s.p,{children:["Removes the item with the given ",(0,n.jsx)(s.a,{href:"/docs/next/api/class-webstorage#web-storage-remove-item-option-name",children:"name"}),". No-op if the item is absent."]}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Usage"})}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",children:"await webStorage.removeItem(name);\n"})}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Arguments"})}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:["\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"name"})," ",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,n.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"web-storage-remove-item-option-name"}),(0,n.jsx)("a",{href:"#web-storage-remove-item-option-name",class:"list-anchor",children:"#"})]}),"\n",(0,n.jsx)(s.p,{children:"Name of the item to remove."}),"\n"]}),"\n"]}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Returns"})}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,n.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"web-storage-remove-item-return"}),(0,n.jsx)("a",{href:"#web-storage-remove-item-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,n.jsx)(s.hr,{}),"\n",(0,n.jsx)(s.h3,{id:"web-storage-set-item",children:"setItem"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.61"}),"\n",(0,n.jsx)("x-search",{children:"webStorage.setItem"}),"\n",(0,n.jsxs)(s.p,{children:["Sets the value for the given ",(0,n.jsx)(s.a,{href:"/docs/next/api/class-webstorage#web-storage-set-item-option-name",children:"name"}),". Overwrites any existing value for that name."]}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Usage"})}),"\n",(0,n.jsx)(s.pre,{children:(0,n.jsx)(s.code,{className:"language-js",children:"await webStorage.setItem(name, value);\n"})}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Arguments"})}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:["\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"name"})," ",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,n.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"web-storage-set-item-option-name"}),(0,n.jsx)("a",{href:"#web-storage-set-item-option-name",class:"list-anchor",children:"#"})]}),"\n",(0,n.jsx)(s.p,{children:"Name of the item to set."}),"\n"]}),"\n",(0,n.jsxs)(s.li,{children:["\n",(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"value"})," ",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,n.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"web-storage-set-item-option-value"}),(0,n.jsx)("a",{href:"#web-storage-set-item-option-value",class:"list-anchor",children:"#"})]}),"\n",(0,n.jsx)(s.p,{children:"New value for the item."}),"\n"]}),"\n"]}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.strong,{children:"Returns"})}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,n.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,n.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"web-storage-set-item-return"}),(0,n.jsx)("a",{href:"#web-storage-set-item-return",class:"list-anchor",children:"#"})]}),"\n"]})]})}function h(e={}){let{wrapper:s}={...(0,a.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(d,{...e})}):d(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.