MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / captureStorageState

Function captureStorageState

lib/utils/trace.js:123–157  ·  view source on GitHub ↗
(helper)

Source from the content-addressed store, hash-verified

121}
122
123async function captureStorageState(helper) {
124 if (typeof helper.grabStorageState === 'function') {
125 try {
126 const state = await helper.grabStorageState()
127 if (state) return state
128 } catch {}
129 }
130
131 const state = { cookies: [], origins: [] }
132
133 if (typeof helper.grabCookie === 'function') {
134 try {
135 const cookies = await helper.grabCookie()
136 if (Array.isArray(cookies)) state.cookies = cookies
137 } catch {}
138 }
139
140 if (typeof helper.executeScript === 'function') {
141 try {
142 const result = await helper.executeScript(() => {
143 const out = { origin: location.origin, items: [] }
144 for (let i = 0; i < localStorage.length; i++) {
145 const name = localStorage.key(i)
146 out.items.push({ name, value: localStorage.getItem(name) })
147 }
148 return out
149 })
150 if (result?.items?.length) {
151 state.origins.push({ origin: result.origin, localStorage: result.items })
152 }
153 } catch {}
154 }
155
156 return state
157}
158
159export async function captureSnapshot(helper, {
160 dir,

Callers 1

captureSnapshotFunction · 0.85

Calls 4

grabStorageStateMethod · 0.80
pushMethod · 0.80
grabCookieMethod · 0.45
executeScriptMethod · 0.45

Tested by

no test coverage detected