microsoft / microsoft/playwright

[Feature] Support web push notification handling/testing

Open
#23,954 6 comments 44 reactions 0 assignees View on GitHub
P3-collecting-feedback
Dominant language
TypeScript
Stars
96.3k
Forks
6.5k
Avg merge
1d 6h
Merged PRs (30d)
180

Description

This is a follow-up to an existing but closed ticket #3301. I was asked to open a new ticket. I specifically care about handling web push notifications. It seems that is somewhat possible in Playwright now (I would love a clarification on what is expected to work and supported and what is explicitly not expected to work [yet]), however there are some issues:

```typescript
import { test } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto(`file://${__dirname}/../index.html`);

page.on('console', msg => console.log(msg.text()));

page.on('dialog', async dialog => {
console.log(dialog.type(), dialog.message());
await dialog.accept();
});

await page.context().grantPermissions(['notifications']);
await page.click('button');
//expect(await page.evaluate(() => Notification.permission)).toBe('granted');
await page.locator('body.shown').waitFor();
});
```

My page's script:
```javascript
const button = document.querySelector('button');

button.addEventListener('click', async () => {
alert('test');

console.log('requesting');
const notificationPermission = await Notification.requestPermission();
console.log('requested', notificationPermission, Notification.permission);
const notification = new Notification('test');
notification.onshow = () => {
document.body.classList.toggle('shown', true);
console.log('shown');
}

console.log('notification', notification);
});
```

When running headless, this gets stuck waiting for the notification's `show` event. It eventually times out. The notification is never shown. The test fails.

When running headed (or as I prefer, headful), the `show` event gets invoked but no actual notifications appears. Even when I tack on a timeout at the end of the test to give the notification time to appear, it never does. The test passes.

The notification doesn't trigger the `dialog` event in any case so I cannot be asserted that way.

Also `Notification.permission` always evaluates to `denied` regardless of `await page.context().grantPermissions(['notifications']);`.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the web notification flow in the TypeScript test shown, focusing on page.context().grantPermissions(['notifications']), Notification.requestPermission(), and the notification show event in headless and headed modes. Define the supported behavior and expected results for permission grants, notification events, and visible notifications, then add coverage for the agreed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
playwright, typescript
Domain
testing, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.