Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bringToFront): enable on all browsers #3052

Merged
merged 1 commit into from
Jul 21, 2020
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
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
3 changes: 3 additions & 0 deletions src/rpc/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ export interface PageChannel extends Channel {
crStopJSCoverage(params?: PageCrStopJSCoverageParams): Promise<PageCrStopJSCoverageResult>;
crStartCSSCoverage(params: PageCrStartCSSCoverageParams): Promise<PageCrStartCSSCoverageResult>;
crStopCSSCoverage(params?: PageCrStopCSSCoverageParams): Promise<PageCrStopCSSCoverageResult>;
bringToFront(params?: PageBringToFrontParams): Promise<PageBringToFrontResult>;
}
export type PageBindingCallEvent = {
binding: BindingCallChannel,
Expand Down Expand Up @@ -798,6 +799,8 @@ export type PageCrStopCSSCoverageResult = {
}[],
}[],
};
export type PageBringToFrontParams = {};
export type PageBringToFrontResult = void;

// ----------- Frame -----------
export type FrameInitializer = {
Expand Down
6 changes: 6 additions & 0 deletions src/rpc/client/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {
return this._attributeToPage(() => this._mainFrame.title());
}

async bringToFront(): Promise<void> {
return this._wrapApiCall('page.bringToFront', async () => {
await this._channel.bringToFront();
});
}

async close(options: { runBeforeUnload?: boolean } = {runBeforeUnload: undefined}) {
return this._wrapApiCall('page.close', async () => {
await this._channel.close(options);
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/protocol.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ interface Page
start: number
end: number

command bringToFront

interface Frame
initializer
url: string
Expand Down
4 changes: 4 additions & 0 deletions src/rpc/server/pageDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ export class PageDispatcher extends Dispatcher<Page, PageInitializer> implements
return { pdf: buffer.toString('base64') };
}

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

async crStartJSCoverage(params: types.JSCoverageOptions): Promise<void> {
const coverage = this._page.coverage as CRCoverage;
await coverage.startJSCoverage(params);
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is strange. Also, nice test 😄

'visible'
);
await browser.close();
});
});