Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to the full browser extension will be documented in this fil

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### Added
- Report elements that have cursor pointer style.

## 0.1.8 - 2025-12-12

### Changed
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rec.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to the recorder browser extension will be documented in this

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

## 0.1.8 - 2025-12-12

### Changed
Expand Down
26 changes: 26 additions & 0 deletions source/ContentScript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,27 @@ function reportNodeElements(
}
}

function reportPointerElements(
source: Element | Document,
fn: (re: ReportedObject) => void
): void {
source.querySelectorAll('*').forEach((element) => {
const {tagName} = element;
const url = window.location.href;
if (
tagName !== 'input' &&
tagName !== 'button' &&
tagName !== 'a' &&
element instanceof Element
) {
const compStyles = window.getComputedStyle(element, 'hover');
if (compStyles.getPropertyValue('cursor') === 'pointer') {
fn(new ReportedElement(element, url));
}
}
});
}

function reportPageLoaded(
doc: Document,
fn: (re: ReportedObject) => void
Expand All @@ -197,6 +218,7 @@ function reportPageLoaded(
reportPageForms(doc, fn);
reportElements(doc.getElementsByTagName('input'), fn);
reportElements(doc.getElementsByTagName('button'), fn);
reportPointerElements(doc, fn);
reportStorage(LOCAL_STORAGE, localStorage, fn);
reportStorage(SESSION_STORAGE, sessionStorage, fn);
}
Expand All @@ -209,10 +231,14 @@ const domMutated = function domMutation(
reportEvent(new ReportedEvent('domMutation'));
reportPageLinks(document, reportObject);
reportPageForms(document, reportObject);
reportPointerElements(document, reportObject);
for (const mutation of mutationList) {
if (mutation.type === 'childList') {
reportNodeElements(mutation.target, 'input', reportObject);
reportNodeElements(mutation.target, 'button', reportObject);
if (mutation.target.nodeType === Node.ELEMENT_NODE) {
reportPointerElements(mutation.target as Element, reportObject);
}
}
}
});
Expand Down
44 changes: 44 additions & 0 deletions test/ContentScript/integrationTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,50 @@ function integrationTests(
]);
});

test.only('Should report pointer elements', async () => {
// Given
await enableZapEvents(server, driver);
server.setRecordZapEvents(false);
const wd = await driver.getWebDriver();
// When
await wd.get(`http://localhost:${_HTTPPORT}/webpages/pointerelements.html`);
await eventsProcessed();
// Then
expect(actualData).toEqual([
reportEvent(
'pageLoad',
'http://localhost:1801/webpages/pointerelements.html'
),
reportObject(
'nodeAdded',
'IMG',
'img1',
'IMG',
'http://localhost:1801/webpages/pointerelements.html',
undefined,
''
),
reportObject(
'nodeAdded',
'DIV',
'div1',
'DIV',
'http://localhost:1801/webpages/pointerelements.html',
undefined,
'Page 1'
),
reportObject(
'nodeAdded',
'DIV',
'div2',
'DIV',
'http://localhost:1801/webpages/pointerelements.html',
undefined,
'Page 2'
),
]);
});

test('Should ignore ZAP div', async () => {
// Given / When
await driver.toggleRecording();
Expand Down
18 changes: 18 additions & 0 deletions test/ContentScript/webpages/pointerelements.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<body>
<style>
.pointer {
cursor: pointer
}
</style>
<div>
<img id="img1" class="pointer" alt="Home" />
<img id="img2" alt="Not Home" />
<div id="div1" class="pointer">Page 1</div>
<div id="div2" class="pointer">Page 2</div>
<div id="div3">Not Page</div>
</div>

</body>
</html>