fix: throw when element handle is detached while waiting for selector (#32961)

This commit is contained in:
Dmitry Gozman 2024-10-04 08:23:25 -07:00 committed by GitHub
parent eaeaa0b158
commit 9f842da8b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 11 deletions

View File

@ -805,6 +805,8 @@ export class Frame extends SdkObject {
return continuePolling;
}
const result = await resolved.injected.evaluateHandle((injected, { info, root }) => {
if (root && !root.isConnected)
throw injected.createStacklessError('Element is not attached to the DOM');
const elements = injected.querySelectorAll(info.parsed, root || document);
const element: Element | undefined = elements[0];
const visible = element ? injected.utils.isElementVisible(element) : false;

View File

@ -328,3 +328,31 @@ it('should fail when navigating while on handle', async ({ page, mode, server })
const error = await body.waitForSelector('div', { __testHookBeforeAdoptNode } as any).catch(e => e);
expect(error.message).toContain(`waiting for locator('div') to be visible`);
});
it('should fail if element handle was detached while waiting', async ({ page, server }) => {
await page.setContent(`<button>hello</button>`);
const button = await page.$('button');
const promise = button.waitForSelector('something').catch(e => e);
await page.waitForTimeout(100);
await page.evaluate(() => document.body.innerText = '');
const error = await promise;
expect(error.message).toContain('Element is not attached to the DOM');
});
it('should succeed if element handle was detached while waiting for hidden', async ({ page, server }) => {
await page.setContent(`<button>hello</button>`);
const button = await page.$('button');
const promise = button.waitForSelector('something', { state: 'hidden' });
await page.waitForTimeout(100);
await page.evaluate(() => document.body.innerText = '');
await promise;
});
it('should succeed if element handle was detached while waiting for detached', async ({ page, server }) => {
await page.setContent(`<button>hello</button>`);
const button = await page.$('button');
const promise = button.waitForSelector('something', { state: 'detached' });
await page.waitForTimeout(100);
await page.evaluate(() => document.body.innerText = '');
await promise;
});

View File

@ -308,17 +308,6 @@ it('click should survive navigation', async ({ page, server }) => {
await promise;
});
it('should fail if element removed while waiting on element handle', async ({ page, server }) => {
it.fixme();
await routeIframe(page);
await page.goto(server.PREFIX + '/iframe.html');
const button = await page.$('button');
const promise = button.waitForSelector('something');
await page.waitForTimeout(100);
await page.evaluate(() => document.body.innerText = '');
await promise;
});
it('should non work for non-frame', async ({ page, server }) => {
await routeIframe(page);
await page.setContent('<div></div>');