diff --git a/CHANGELOG.md b/CHANGELOG.md index 14c136c..34c7e10 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 +- Report index of the forms. + ## 0.0.9 - 2024-11-28 ### Added diff --git a/source/types/ReportedModel.ts b/source/types/ReportedModel.ts index e28de8c..3b5baa2 100644 --- a/source/types/ReportedModel.ts +++ b/source/types/ReportedModel.ts @@ -113,6 +113,8 @@ class ReportedElement extends ReportedObject { // This gets the full URL rather than a relative one const a: HTMLAnchorElement = element as HTMLAnchorElement; this.href = a.toString(); + } else if (element.tagName === 'FORM') { + this.formId = Array.prototype.slice.call(document.forms).indexOf(element); } else if (element.tagName === 'INPUT') { // Capture extra useful info for input elements const input: HTMLInputElement = element as HTMLInputElement; diff --git a/test/ContentScript/unitTests.test.ts b/test/ContentScript/unitTests.test.ts index eae39bd..b784eec 100644 --- a/test/ContentScript/unitTests.test.ts +++ b/test/ContentScript/unitTests.test.ts @@ -169,10 +169,10 @@ test('Report page forms', () => { // Then expect(mockFn.mock.calls.length).toBe(2); expect(mockFn.mock.calls[0][0].toNonTimestampString()).toBe( - '{"type":"nodeAdded","tagName":"FORM","id":"form1","nodeName":"FORM","url":"http://localhost/","text":"Content1"}' + '{"type":"nodeAdded","tagName":"FORM","id":"form1","nodeName":"FORM","url":"http://localhost/","text":"Content1","formId":-1}' ); expect(mockFn.mock.calls[1][0].toNonTimestampString()).toBe( - '{"type":"nodeAdded","tagName":"FORM","id":"form2","nodeName":"FORM","url":"http://localhost/","text":"Content2"}' + '{"type":"nodeAdded","tagName":"FORM","id":"form2","nodeName":"FORM","url":"http://localhost/","text":"Content2","formId":-1}' ); }); @@ -263,7 +263,7 @@ test('Reported page loaded', () => { '{"type":"nodeAdded","tagName":"AREA","id":"","nodeName":"AREA","url":"http://localhost/","href":"https://www.example.com/1","text":""}' ); expect(mockFn.mock.calls[2][0].toNonTimestampString()).toBe( - '{"type":"nodeAdded","tagName":"FORM","id":"form1","nodeName":"FORM","url":"http://localhost/","text":"FormContent"}' + '{"type":"nodeAdded","tagName":"FORM","id":"form1","nodeName":"FORM","url":"http://localhost/","text":"FormContent","formId":-1}' ); expect(mockFn.mock.calls[3][0].toNonTimestampString()).toBe( '{"type":"nodeAdded","tagName":"INPUT","id":"input1","nodeName":"INPUT","url":"http://localhost/","text":"default","tagType":"text"}'