diff --git a/CHANGELOG.md b/CHANGELOG.md index b34c46b..9db97ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this add-on will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## Unreleased + +### Changed +- Poll for storage changes. + ## 0.0.7 - 2023-10-23 ### Changed diff --git a/README.md b/README.md index 81ef487..80a8e2e 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Then run the following: - `yarn run build:firefox` to build firefox addon - `yarn run build:opera` to build opera extension - `yarn run build` builds and packs extensions all at once to extension/ directory +- `yarn run lint` to lint the code +- `yarn run test` to run the test suite (you should not have anything listening on port 8080) ### Development diff --git a/source/ContentScript/index.ts b/source/ContentScript/index.ts index 01833a5..1309430 100644 --- a/source/ContentScript/index.ts +++ b/source/ContentScript/index.ts @@ -234,6 +234,11 @@ function enableExtension(): void { subtree: true, }); + setInterval(() => { + // Have to poll to pickup storage changes in a timely fashion + reportAllStorage(); + }, 500); + // This is needed for more traditional apps reportPageLoaded(document, reportObject); } diff --git a/test/ContentScript/integrationTests.test.ts b/test/ContentScript/integrationTests.test.ts index 76b7a46..e03f8d8 100644 --- a/test/ContentScript/integrationTests.test.ts +++ b/test/ContentScript/integrationTests.test.ts @@ -300,9 +300,8 @@ function integrationTests( await page.close(); // Then const expectedData = - '["{\\"action\\":{\\"action\\":\\"reportEvent\\"},\\"body\\":{\\"eventJson\\":\\"{TIMESTAMP,\\"eventName\\":\\"pageLoad\\",\\"url\\":\\"http://localhost:1801/webpages/localStorage.html\\",\\"count\\":1}\\",\\"apikey\\":\\"not set\\"}}",' + - '"{\\"action\\":{\\"action\\":\\"reportObject\\"},\\"body\\":{\\"objectJson\\":\\"{TIMESTAMP,\\"type\\":\\"localStorage\\",\\"tagName\\":\\"\\",\\"id\\":\\"test\\",\\"nodeName\\":\\"\\",\\"url\\":\\"http://localhost:1801/webpages/localStorage.html\\",\\"text\\":\\"localData\\"}\\",\\"apikey\\":\\"not set\\"}}"]'; - expect(JSON.stringify(Array.from(actualData))).toBe(expectedData); + '"{\\"action\\":{\\"action\\":\\"reportObject\\"},\\"body\\":{\\"objectJson\\":\\"{TIMESTAMP,\\"type\\":\\"localStorage\\",\\"tagName\\":\\"\\",\\"id\\":\\"test\\",\\"nodeName\\":\\"\\",\\"url\\":\\"http://localhost:1801/webpages/localStorage.html\\",\\"text\\":\\"localData\\"}\\",\\"apikey\\":\\"not set\\"}}"'; + expect(JSON.stringify(Array.from(actualData))).toContain(expectedData); }); test('Should record set sessionStorage', async () => { @@ -318,9 +317,44 @@ function integrationTests( await page.close(); // Then const expectedData = - '["{\\"action\\":{\\"action\\":\\"reportEvent\\"},\\"body\\":{\\"eventJson\\":\\"{TIMESTAMP,\\"eventName\\":\\"pageLoad\\",\\"url\\":\\"http://localhost:1801/webpages/sessionStorage.html\\",\\"count\\":1}\\",\\"apikey\\":\\"not set\\"}}",' + - '"{\\"action\\":{\\"action\\":\\"reportObject\\"},\\"body\\":{\\"objectJson\\":\\"{TIMESTAMP,\\"type\\":\\"sessionStorage\\",\\"tagName\\":\\"\\",\\"id\\":\\"test\\",\\"nodeName\\":\\"\\",\\"url\\":\\"http://localhost:1801/webpages/sessionStorage.html\\",\\"text\\":\\"sessionData\\"}\\",\\"apikey\\":\\"not set\\"}}"]'; - expect(JSON.stringify(Array.from(actualData))).toBe(expectedData); + '"{\\"action\\":{\\"action\\":\\"reportObject\\"},\\"body\\":{\\"objectJson\\":\\"{TIMESTAMP,\\"type\\":\\"sessionStorage\\",\\"tagName\\":\\"\\",\\"id\\":\\"test\\",\\"nodeName\\":\\"\\",\\"url\\":\\"http://localhost:1801/webpages/sessionStorage.html\\",\\"text\\":\\"sessionData\\"}\\",\\"apikey\\":\\"not set\\"}}"'; + expect(JSON.stringify(Array.from(actualData))).toContain(expectedData); + }); + + test('Should record set localStorage with page open', async () => { + // Given / When + server = getFakeZapServer(actualData, _JSONPORT, true); + const context = await driver.getContext(_JSONPORT); + const page = await context.newPage(); + await page.goto( + `http://localhost:${_HTTPPORT}/webpages/localStorageDelay.html` + ); + await page.waitForLoadState('networkidle'); + await page.waitForTimeout(2000); + // Then + const expectedData = + '"{\\"action\\":{\\"action\\":\\"reportObject\\"},\\"body\\":{\\"objectJson\\":\\"{TIMESTAMP,\\"type\\":\\"localStorage\\",\\"tagName\\":\\"\\",\\"id\\":\\"test\\",\\"nodeName\\":\\"\\",\\"url\\":\\"http://localhost:1801/webpages/localStorageDelay.html\\",\\"text\\":\\"localData\\"}\\",\\"apikey\\":\\"not set\\"}}"'; + expect(JSON.stringify(Array.from(actualData))).toContain(expectedData); + // Tidy up + await page.close(); + }); + + test('Should record set sessionStorage with page open', async () => { + // Given / When + server = getFakeZapServer(actualData, _JSONPORT); + const context = await driver.getContext(_JSONPORT); + const page = await context.newPage(); + await page.goto( + `http://localhost:${_HTTPPORT}/webpages/sessionStorageDelay.html` + ); + await page.waitForLoadState('networkidle'); + await page.waitForTimeout(2000); + // Then + const expectedData = + '"{\\"action\\":{\\"action\\":\\"reportObject\\"},\\"body\\":{\\"objectJson\\":\\"{TIMESTAMP,\\"type\\":\\"sessionStorage\\",\\"tagName\\":\\"\\",\\"id\\":\\"test\\",\\"nodeName\\":\\"\\",\\"url\\":\\"http://localhost:1801/webpages/sessionStorageDelay.html\\",\\"text\\":\\"sessionData\\"}\\",\\"apikey\\":\\"not set\\"}}"'; + expect(JSON.stringify(Array.from(actualData))).toContain(expectedData); + // Tidy up + await page.close(); }); test('Should record dup added link once ', async () => { diff --git a/test/ContentScript/webpages/localStorageDelay.html b/test/ContentScript/webpages/localStorageDelay.html new file mode 100644 index 0000000..9dcf98a --- /dev/null +++ b/test/ContentScript/webpages/localStorageDelay.html @@ -0,0 +1,13 @@ + + + + Document + + + + + \ No newline at end of file diff --git a/test/ContentScript/webpages/sessionStorageDelay.html b/test/ContentScript/webpages/sessionStorageDelay.html new file mode 100644 index 0000000..df07b5f --- /dev/null +++ b/test/ContentScript/webpages/sessionStorageDelay.html @@ -0,0 +1,13 @@ + + + + Document + + + + + \ No newline at end of file