fix: capture IndexedDB object-store record fingerprints (#809)
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
@@ -256,7 +256,6 @@ const addIndexedDbRecords = async (
|
||||
securityOrigin: input.origin,
|
||||
databaseName: input.databaseName,
|
||||
objectStoreName: input.objectStoreName,
|
||||
indexName: "",
|
||||
skipCount,
|
||||
pageSize: STORAGE_ENTRY_PAGE_SIZE,
|
||||
},
|
||||
@@ -290,7 +289,10 @@ const addIndexedDbRecords = async (
|
||||
primaryKey,
|
||||
},
|
||||
value,
|
||||
complete: remoteObjectComplete(entry.value),
|
||||
complete:
|
||||
remoteObjectComplete(entry.key) &&
|
||||
remoteObjectComplete(entry.primaryKey) &&
|
||||
remoteObjectComplete(entry.value),
|
||||
});
|
||||
}
|
||||
if (result.hasMore !== true) return;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { CdpBrowserProvider } from "../../../src/browser/CdpBrowserProvider.js";
|
||||
import { inspectWebPageInputSchema } from "../../../src/domain/browserObservation.js";
|
||||
import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js";
|
||||
import { trackBrowser } from "./cdpBrowserProvider.support.js";
|
||||
|
||||
it.each([false, true])(
|
||||
"captures object-store records with Date keys: %s",
|
||||
async (dateKeys) => {
|
||||
const browser = await startFakeCdpBrowser({ indexedDbDateKeys: dateKeys });
|
||||
trackBrowser(browser);
|
||||
const result = await new CdpBrowserProvider().inspectPage(
|
||||
inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
include_storage_keys: true,
|
||||
include_storage_fingerprints: true,
|
||||
}),
|
||||
);
|
||||
if (!result.ok) throw result.error;
|
||||
|
||||
const requests = browser.commands.filter(
|
||||
({ method }) => method === "IndexedDB.requestData",
|
||||
);
|
||||
expect(requests.length).toBeGreaterThan(0);
|
||||
for (const request of requests)
|
||||
expect(request.params).not.toHaveProperty("indexName");
|
||||
const records = result.value.storage.content_fingerprints.filter(
|
||||
({ scope }) => scope === "indexed_db_record",
|
||||
);
|
||||
expect(records).toHaveLength(1);
|
||||
expect(records[0]?.complete).toBe(!dateKeys);
|
||||
expect(result.value.storage.fingerprints_complete).toBe(!dateKeys);
|
||||
expect(JSON.stringify(result.value.storage)).not.toContain(
|
||||
"indexed-db-secret",
|
||||
);
|
||||
},
|
||||
);
|
||||
+21
-4
@@ -37,7 +37,7 @@ export const resultFor = (
|
||||
case "IndexedDB.requestDatabase":
|
||||
return indexedDbDatabaseResult(command);
|
||||
case "IndexedDB.requestData":
|
||||
return indexedDbDataResult();
|
||||
return indexedDbDataResult(options);
|
||||
case "CacheStorage.requestCacheNames":
|
||||
return cacheStorageResult(options);
|
||||
case "CacheStorage.requestEntries":
|
||||
@@ -154,17 +154,34 @@ const indexedDbDatabaseResult = (command: FakeCdpCommand) => ({
|
||||
},
|
||||
});
|
||||
|
||||
const indexedDbDataResult = () => ({
|
||||
const indexedDbDataResult = (options: FakeOptions) => ({
|
||||
objectStoreDataEntries: [
|
||||
{
|
||||
key: { type: "string", value: "row-1" },
|
||||
primaryKey: { type: "string", value: "row-1" },
|
||||
key: indexedDbKey(options),
|
||||
primaryKey: indexedDbKey(options),
|
||||
value: { type: "string", value: "indexed-db-secret" },
|
||||
},
|
||||
],
|
||||
hasMore: false,
|
||||
});
|
||||
|
||||
const indexedDbKey = (options: FakeOptions) =>
|
||||
options.indexedDbDateKeys === true
|
||||
? {
|
||||
type: "object",
|
||||
subtype: "date",
|
||||
className: "Date",
|
||||
description: "Thu Jan 01 1970 00:00:00 GMT+0000",
|
||||
objectId: "owned-date-key",
|
||||
preview: {
|
||||
type: "object",
|
||||
subtype: "date",
|
||||
overflow: false,
|
||||
properties: [],
|
||||
},
|
||||
}
|
||||
: { type: "string", value: "row-1" };
|
||||
|
||||
const cacheStorageResult = (options: FakeOptions) => ({
|
||||
caches: [
|
||||
{ cacheName: "assets-v1", cacheId: "secret-id" },
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ export interface FakeOptions {
|
||||
readonly navigateDuringScreenshotUrl?: string;
|
||||
readonly screenshotDocumentLoader?: string;
|
||||
readonly extraCollections?: boolean;
|
||||
readonly indexedDbDateKeys?: boolean;
|
||||
readonly foreignSessionEvents?: boolean;
|
||||
readonly redirectToDisallowedOrigin?: boolean;
|
||||
readonly unrelatedWorker?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user