Skip to content

Commit

Permalink
feat(bringToFront): enable on all browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Jul 21, 2020
1 parent d1f937d commit 012a488
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
{
"name": "firefox",
"revision": "1128"
"revision": "1134"
},
{
"name": "webkit",
Expand Down
9 changes: 9 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ page.removeListener('request', logRequest);
- [page.addInitScript(script[, arg])](#pageaddinitscriptscript-arg)
- [page.addScriptTag(options)](#pageaddscripttagoptions)
- [page.addStyleTag(options)](#pageaddstyletagoptions)
- [page.bringToFront()](#pagebringtofront)
- [page.check(selector, [options])](#pagecheckselector-options)
- [page.click(selector[, options])](#pageclickselector-options)
- [page.close([options])](#pagecloseoptions)
Expand Down Expand Up @@ -1007,6 +1008,14 @@ Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<s

Shortcut for [page.mainFrame().addStyleTag(options)](#frameaddstyletagoptions).


#### page.bringToFront()

- returns: <[Promise]>

Brings page to front (activates tab).


#### page.check(selector, [options])
- `selector` <[string]> A selector to search for checkbox or radio button to check. If there are multiple elements satisfying the selector, the first will be checked. See [working with selectors](#working-with-selectors) for more details.
- `options` <[Object]>
Expand Down
4 changes: 4 additions & 0 deletions src/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export class CRPage implements PageDelegate {
await this._mainFrameSession._updateViewport();
}

async bringToFront(): Promise<void> {
await this._mainFrameSession._client.send('Page.bringToFront');
}

async updateEmulateMedia(): Promise<void> {
await this._forAllFrameSessions(frame => frame._updateEmulateMedia());
}
Expand Down
4 changes: 4 additions & 0 deletions src/firefox/ffPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ export class FFPage implements PageDelegate {
});
}

async bringToFront(): Promise<void> {
await this._session.send('Page.bringToFront', {});
}

async updateEmulateMedia(): Promise<void> {
const colorScheme = this._page._state.colorScheme || this._browserContext._options.colorScheme || 'light';
await this._session.send('Page.setEmulatedMedia', {
Expand Down
5 changes: 5 additions & 0 deletions src/firefox/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ export module Protocol {
}|null;
};
export type setViewportSizeReturnValue = void;
export type bringToFrontParameters = {
};
export type bringToFrontReturnValue = void;
export type setEmulatedMediaParameters = {
type?: ("screen"|"print"|"");
colorScheme?: ("dark"|"light"|"no-preference");
Expand Down Expand Up @@ -963,6 +966,7 @@ export module Protocol {
"Page.setFileInputFiles": Page.setFileInputFilesParameters;
"Page.addBinding": Page.addBindingParameters;
"Page.setViewportSize": Page.setViewportSizeParameters;
"Page.bringToFront": Page.bringToFrontParameters;
"Page.setEmulatedMedia": Page.setEmulatedMediaParameters;
"Page.setCacheDisabled": Page.setCacheDisabledParameters;
"Page.describeNode": Page.describeNodeParameters;
Expand Down Expand Up @@ -1033,6 +1037,7 @@ export module Protocol {
"Page.setFileInputFiles": Page.setFileInputFilesReturnValue;
"Page.addBinding": Page.addBindingReturnValue;
"Page.setViewportSize": Page.setViewportSizeReturnValue;
"Page.bringToFront": Page.bringToFrontReturnValue;
"Page.setEmulatedMedia": Page.setEmulatedMediaReturnValue;
"Page.setCacheDisabled": Page.setCacheDisabledReturnValue;
"Page.describeNode": Page.describeNodeReturnValue;
Expand Down
5 changes: 5 additions & 0 deletions src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface PageDelegate {
updateEmulateMedia(): Promise<void>;
updateRequestInterception(): Promise<void>;
setFileChooserIntercepted(enabled: boolean): Promise<void>;
bringToFront(): Promise<void>;

canScreenshotOutsideViewport(): boolean;
resetViewport(): Promise<void>; // Only called if canScreenshotOutsideViewport() returns false.
Expand Down Expand Up @@ -403,6 +404,10 @@ export class Page extends EventEmitter {
return this._state.viewportSize;
}

async bringToFront(): Promise<void> {
await this._delegate.bringToFront();
}

async evaluate<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<R>;
async evaluate<R>(pageFunction: js.Func1<void, R>, arg?: any): Promise<R>;
async evaluate<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<R> {
Expand Down
6 changes: 6 additions & 0 deletions src/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,12 @@ export class WKPage implements PageDelegate {
await this._updateViewport();
}

async bringToFront(): Promise<void> {
this._pageProxySession.send('Target.activate', {
targetId: this._session.sessionId
});
}

async _updateViewport(): Promise<void> {
const options = this._browserContext._options;
const viewportSize = this._page._state.viewportSize;
Expand Down
18 changes: 18 additions & 0 deletions test/headful.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,22 @@ describe('Headful', function() {
await context.close();
await browser.close();
});
it('Page.bringToFront should work', async ({browserType, defaultBrowserOptions}) => {
const browser = await browserType.launch({...defaultBrowserOptions, headless: false });
const page1 = await browser.newPage();
await page1.setContent('Page1')
const page2 = await browser.newPage();
await page2.setContent('Page2')

await page1.bringToFront();
expect(await page1.evaluate('document.visibilityState')).toBe('visible');
expect(await page2.evaluate('document.visibilityState')).toBe('visible');

await page2.bringToFront();
expect(await page1.evaluate('document.visibilityState')).toBe('visible');
expect(await page2.evaluate('document.visibilityState')).toBe(
'visible'
);
await browser.close();
});
});

0 comments on commit 012a488

Please sign in to comment.