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,
|
securityOrigin: input.origin,
|
||||||
databaseName: input.databaseName,
|
databaseName: input.databaseName,
|
||||||
objectStoreName: input.objectStoreName,
|
objectStoreName: input.objectStoreName,
|
||||||
indexName: "",
|
|
||||||
skipCount,
|
skipCount,
|
||||||
pageSize: STORAGE_ENTRY_PAGE_SIZE,
|
pageSize: STORAGE_ENTRY_PAGE_SIZE,
|
||||||
},
|
},
|
||||||
@@ -290,7 +289,10 @@ const addIndexedDbRecords = async (
|
|||||||
primaryKey,
|
primaryKey,
|
||||||
},
|
},
|
||||||
value,
|
value,
|
||||||
complete: remoteObjectComplete(entry.value),
|
complete:
|
||||||
|
remoteObjectComplete(entry.key) &&
|
||||||
|
remoteObjectComplete(entry.primaryKey) &&
|
||||||
|
remoteObjectComplete(entry.value),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (result.hasMore !== true) return;
|
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":
|
case "IndexedDB.requestDatabase":
|
||||||
return indexedDbDatabaseResult(command);
|
return indexedDbDatabaseResult(command);
|
||||||
case "IndexedDB.requestData":
|
case "IndexedDB.requestData":
|
||||||
return indexedDbDataResult();
|
return indexedDbDataResult(options);
|
||||||
case "CacheStorage.requestCacheNames":
|
case "CacheStorage.requestCacheNames":
|
||||||
return cacheStorageResult(options);
|
return cacheStorageResult(options);
|
||||||
case "CacheStorage.requestEntries":
|
case "CacheStorage.requestEntries":
|
||||||
@@ -154,17 +154,34 @@ const indexedDbDatabaseResult = (command: FakeCdpCommand) => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const indexedDbDataResult = () => ({
|
const indexedDbDataResult = (options: FakeOptions) => ({
|
||||||
objectStoreDataEntries: [
|
objectStoreDataEntries: [
|
||||||
{
|
{
|
||||||
key: { type: "string", value: "row-1" },
|
key: indexedDbKey(options),
|
||||||
primaryKey: { type: "string", value: "row-1" },
|
primaryKey: indexedDbKey(options),
|
||||||
value: { type: "string", value: "indexed-db-secret" },
|
value: { type: "string", value: "indexed-db-secret" },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
hasMore: false,
|
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) => ({
|
const cacheStorageResult = (options: FakeOptions) => ({
|
||||||
caches: [
|
caches: [
|
||||||
{ cacheName: "assets-v1", cacheId: "secret-id" },
|
{ cacheName: "assets-v1", cacheId: "secret-id" },
|
||||||
|
|||||||
+1
@@ -44,6 +44,7 @@ export interface FakeOptions {
|
|||||||
readonly navigateDuringScreenshotUrl?: string;
|
readonly navigateDuringScreenshotUrl?: string;
|
||||||
readonly screenshotDocumentLoader?: string;
|
readonly screenshotDocumentLoader?: string;
|
||||||
readonly extraCollections?: boolean;
|
readonly extraCollections?: boolean;
|
||||||
|
readonly indexedDbDateKeys?: boolean;
|
||||||
readonly foreignSessionEvents?: boolean;
|
readonly foreignSessionEvents?: boolean;
|
||||||
readonly redirectToDisallowedOrigin?: boolean;
|
readonly redirectToDisallowedOrigin?: boolean;
|
||||||
readonly unrelatedWorker?: boolean;
|
readonly unrelatedWorker?: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user