Skip to content

Commit 24fca1a

Browse files
committed
fix(highlight): highlight Top Layer elements
1 parent a41122d commit 24fca1a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packages/playwright-core/src/server/injected/highlight.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class Highlight {
5555
const document = injectedScript.document;
5656
this._isUnderTest = injectedScript.isUnderTest;
5757
this._glassPaneElement = document.createElement('x-pw-glass');
58+
this._glassPaneElement.popover = 'manual';
5859
this._glassPaneElement.style.position = 'fixed';
5960
this._glassPaneElement.style.top = '0';
6061
this._glassPaneElement.style.right = '0';
@@ -64,6 +65,12 @@ export class Highlight {
6465
this._glassPaneElement.style.pointerEvents = 'none';
6566
this._glassPaneElement.style.display = 'flex';
6667
this._glassPaneElement.style.backgroundColor = 'transparent';
68+
this._glassPaneElement.style.width = 'inherit';
69+
this._glassPaneElement.style.height = 'inherit';
70+
this._glassPaneElement.style.padding = '0';
71+
this._glassPaneElement.style.margin = '0';
72+
this._glassPaneElement.style.border = 'none';
73+
this._glassPaneElement.style.overflow = 'hidden';
6774
for (const eventName of ['click', 'auxclick', 'dragstart', 'input', 'keydown', 'keyup', 'pointerdown', 'pointerup', 'mousedown', 'mouseup', 'mouseleave', 'focus', 'scroll']) {
6875
this._glassPaneElement.addEventListener(eventName, e => {
6976
e.stopPropagation();
@@ -83,6 +90,8 @@ export class Highlight {
8390

8491
install() {
8592
this._injectedScript.document.documentElement.appendChild(this._glassPaneElement);
93+
// Popover is not supported in WebKit-macOS < 14.0
94+
this._glassPaneElement.showPopover?.();
8695
}
8796

8897
setLanguage(language: Language) {
@@ -99,6 +108,8 @@ export class Highlight {
99108
uninstall() {
100109
if (this._rafRequest)
101110
cancelAnimationFrame(this._rafRequest);
111+
// Popover is not supported in WebKit-macOS < 14.0
112+
this._glassPaneElement.hidePopover?.();
102113
this._glassPaneElement.remove();
103114
}
104115

tests/page/page-screenshot.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,34 @@ it.describe('page screenshot', () => {
482482
})).toMatchSnapshot('should-mask-inside-iframe.png');
483483
});
484484

485+
it('should mask inside <dialog />', async ({ page, server, browserName }) => {
486+
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29878' });
487+
it.skip(browserName === 'webkit' && process.platform === 'darwin' && parseInt(os.release().split('.')[0], 10) < 23, 'SDKAlignedBehavior::PopoverAttributeEnabled is only enabled in macOS 14.0+');
488+
await page.setViewportSize({ width: 500, height: 500 });
489+
await page.goto(server.PREFIX + '/grid.html');
490+
await page.evaluate(() => {
491+
const elements = document.body.innerHTML;
492+
document.body.innerHTML = '';
493+
// Move all the elements of the body (grid elements) into a <dialog /> which lives on the Top-Layer.
494+
const dialog = document.createElement('dialog');
495+
dialog.style.padding = '0';
496+
dialog.style.margin = '0';
497+
dialog.style.border = 'none';
498+
dialog.style.maxWidth = 'inherit';
499+
dialog.style.maxHeight = 'inherit';
500+
dialog.style.outline = 'none';
501+
document.body.appendChild(dialog);
502+
dialog.innerHTML = elements;
503+
dialog.showModal();
504+
});
505+
expect(await page.screenshot({
506+
mask: [
507+
page.locator('div').nth(5),
508+
page.frameLocator('#frame1').locator('div').nth(12),
509+
],
510+
})).toMatchSnapshot('should-mask-inside-iframe.png');
511+
});
512+
485513
it('should mask in parallel', async ({ page, server }) => {
486514
await page.setViewportSize({ width: 500, height: 500 });
487515
await attachFrame(page, 'frame1', server.PREFIX + '/grid.html');

0 commit comments

Comments
 (0)