mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
parent
a16eaf584a
commit
18fdf927b7
@ -18,7 +18,7 @@ import * as mime from 'mime';
|
|||||||
import * as injectedScriptSource from '../generated/injectedScriptSource';
|
import * as injectedScriptSource from '../generated/injectedScriptSource';
|
||||||
import * as channels from '../protocol/channels';
|
import * as channels from '../protocol/channels';
|
||||||
import { isSessionClosedError } from './protocolError';
|
import { isSessionClosedError } from './protocolError';
|
||||||
import { ScreenshotMaskOption } from './screenshotter';
|
import { ScreenshotOptions } from './screenshotter';
|
||||||
import * as frames from './frames';
|
import * as frames from './frames';
|
||||||
import type { InjectedScript, InjectedScriptPoll, LogEntry, HitTargetInterceptionResult } from './injected/injectedScript';
|
import type { InjectedScript, InjectedScriptPoll, LogEntry, HitTargetInterceptionResult } from './injected/injectedScript';
|
||||||
import { CallMetadata } from './instrumentation';
|
import { CallMetadata } from './instrumentation';
|
||||||
@ -27,6 +27,7 @@ import { Page } from './page';
|
|||||||
import { Progress, ProgressController } from './progress';
|
import { Progress, ProgressController } from './progress';
|
||||||
import { SelectorInfo } from './selectors';
|
import { SelectorInfo } from './selectors';
|
||||||
import * as types from './types';
|
import * as types from './types';
|
||||||
|
import { TimeoutOptions } from '../common/types';
|
||||||
|
|
||||||
type SetInputFilesFiles = channels.ElementHandleSetInputFilesParams['files'];
|
type SetInputFilesFiles = channels.ElementHandleSetInputFilesParams['files'];
|
||||||
type ActionName = 'click' | 'hover' | 'dblclick' | 'tap' | 'move and up' | 'move and down';
|
type ActionName = 'click' | 'hover' | 'dblclick' | 'tap' | 'move and up' | 'move and down';
|
||||||
@ -773,7 +774,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
|||||||
return this._page._delegate.getBoundingBox(this);
|
return this._page._delegate.getBoundingBox(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
async screenshot(metadata: CallMetadata, options: types.ElementScreenshotOptions & ScreenshotMaskOption = {}): Promise<Buffer> {
|
async screenshot(metadata: CallMetadata, options: ScreenshotOptions & TimeoutOptions = {}): Promise<Buffer> {
|
||||||
const controller = new ProgressController(metadata, this);
|
const controller = new ProgressController(metadata, this);
|
||||||
return controller.run(
|
return controller.run(
|
||||||
progress => this._page._screenshotter.screenshotElement(progress, this, options),
|
progress => this._page._screenshotter.screenshotElement(progress, this, options),
|
||||||
|
@ -20,7 +20,7 @@ import * as frames from './frames';
|
|||||||
import * as input from './input';
|
import * as input from './input';
|
||||||
import * as js from './javascript';
|
import * as js from './javascript';
|
||||||
import * as network from './network';
|
import * as network from './network';
|
||||||
import { Screenshotter, ScreenshotMaskOption } from './screenshotter';
|
import { Screenshotter, ScreenshotOptions } from './screenshotter';
|
||||||
import { TimeoutSettings } from '../utils/timeoutSettings';
|
import { TimeoutSettings } from '../utils/timeoutSettings';
|
||||||
import * as types from './types';
|
import * as types from './types';
|
||||||
import { BrowserContext } from './browserContext';
|
import { BrowserContext } from './browserContext';
|
||||||
@ -35,6 +35,7 @@ import { SelectorInfo, Selectors } from './selectors';
|
|||||||
import { CallMetadata, SdkObject } from './instrumentation';
|
import { CallMetadata, SdkObject } from './instrumentation';
|
||||||
import { Artifact } from './artifact';
|
import { Artifact } from './artifact';
|
||||||
import { ParsedSelector } from './common/selectorParser';
|
import { ParsedSelector } from './common/selectorParser';
|
||||||
|
import { TimeoutOptions } from '../common/types';
|
||||||
|
|
||||||
export interface PageDelegate {
|
export interface PageDelegate {
|
||||||
readonly rawMouse: input.RawMouse;
|
readonly rawMouse: input.RawMouse;
|
||||||
@ -424,7 +425,7 @@ export class Page extends SdkObject {
|
|||||||
route.continue();
|
route.continue();
|
||||||
}
|
}
|
||||||
|
|
||||||
async screenshot(metadata: CallMetadata, options: types.ScreenshotOptions & ScreenshotMaskOption = {}): Promise<Buffer> {
|
async screenshot(metadata: CallMetadata, options: ScreenshotOptions & TimeoutOptions): Promise<Buffer> {
|
||||||
const controller = new ProgressController(metadata, this);
|
const controller = new ProgressController(metadata, this);
|
||||||
return controller.run(
|
return controller.run(
|
||||||
progress => this._screenshotter.screenshotPage(progress, options),
|
progress => this._screenshotter.screenshotPage(progress, options),
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as dom from './dom';
|
import * as dom from './dom';
|
||||||
|
import { Rect } from '../common/types';
|
||||||
import { helper } from './helper';
|
import { helper } from './helper';
|
||||||
import { Page } from './page';
|
import { Page } from './page';
|
||||||
import { Frame } from './frames';
|
import { Frame } from './frames';
|
||||||
@ -31,8 +32,14 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ScreenshotMaskOption = {
|
export type ScreenshotOptions = {
|
||||||
|
type?: 'png' | 'jpeg',
|
||||||
|
quality?: number,
|
||||||
|
omitBackground?: boolean,
|
||||||
|
disableAnimations?: boolean,
|
||||||
mask?: { frame: Frame, selector: string}[],
|
mask?: { frame: Frame, selector: string}[],
|
||||||
|
fullPage?: boolean,
|
||||||
|
clip?: Rect,
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Screenshotter {
|
export class Screenshotter {
|
||||||
@ -72,7 +79,7 @@ export class Screenshotter {
|
|||||||
return fullPageSize!;
|
return fullPageSize!;
|
||||||
}
|
}
|
||||||
|
|
||||||
async screenshotPage(progress: Progress, options: types.ScreenshotOptions & ScreenshotMaskOption): Promise<Buffer> {
|
async screenshotPage(progress: Progress, options: ScreenshotOptions): Promise<Buffer> {
|
||||||
const format = validateScreenshotOptions(options);
|
const format = validateScreenshotOptions(options);
|
||||||
return this._queue.postTask(async () => {
|
return this._queue.postTask(async () => {
|
||||||
const { viewportSize } = await this._originalViewportSize(progress);
|
const { viewportSize } = await this._originalViewportSize(progress);
|
||||||
@ -99,7 +106,7 @@ export class Screenshotter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async screenshotElement(progress: Progress, handle: dom.ElementHandle, options: types.ElementScreenshotOptions & ScreenshotMaskOption = {}): Promise<Buffer> {
|
async screenshotElement(progress: Progress, handle: dom.ElementHandle, options: ScreenshotOptions): Promise<Buffer> {
|
||||||
const format = validateScreenshotOptions(options);
|
const format = validateScreenshotOptions(options);
|
||||||
return this._queue.postTask(async () => {
|
return this._queue.postTask(async () => {
|
||||||
const { viewportSize } = await this._originalViewportSize(progress);
|
const { viewportSize } = await this._originalViewportSize(progress);
|
||||||
@ -215,7 +222,7 @@ export class Screenshotter {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async _maskElements(progress: Progress, options: ScreenshotMaskOption) {
|
async _maskElements(progress: Progress, options: ScreenshotOptions) {
|
||||||
const framesToParsedSelectors: MultiMap<Frame, ParsedSelector> = new MultiMap();
|
const framesToParsedSelectors: MultiMap<Frame, ParsedSelector> = new MultiMap();
|
||||||
await Promise.all((options.mask || []).map(async ({ frame, selector }) => {
|
await Promise.all((options.mask || []).map(async ({ frame, selector }) => {
|
||||||
const pair = await frame.resolveFrameForSelectorNoWait(selector);
|
const pair = await frame.resolveFrameForSelectorNoWait(selector);
|
||||||
@ -230,7 +237,7 @@ export class Screenshotter {
|
|||||||
progress.cleanupWhenAborted(() => this._page.hideHighlight());
|
progress.cleanupWhenAborted(() => this._page.hideHighlight());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _screenshot(progress: Progress, format: 'png' | 'jpeg', documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, fitsViewport: boolean | undefined, options: types.ElementScreenshotOptions & ScreenshotMaskOption): Promise<Buffer> {
|
private async _screenshot(progress: Progress, format: 'png' | 'jpeg', documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, fitsViewport: boolean | undefined, options: ScreenshotOptions): Promise<Buffer> {
|
||||||
if ((options as any).__testHookBeforeScreenshot)
|
if ((options as any).__testHookBeforeScreenshot)
|
||||||
await (options as any).__testHookBeforeScreenshot();
|
await (options as any).__testHookBeforeScreenshot();
|
||||||
progress.throwIfAborted(); // Screenshotting is expensive - avoid extra work.
|
progress.throwIfAborted(); // Screenshotting is expensive - avoid extra work.
|
||||||
@ -287,7 +294,7 @@ function trimClipToSize(clip: types.Rect, size: types.Size): types.Rect {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateScreenshotOptions(options: types.ScreenshotOptions): 'png' | 'jpeg' {
|
function validateScreenshotOptions(options: ScreenshotOptions): 'png' | 'jpeg' {
|
||||||
let format: 'png' | 'jpeg' | null = null;
|
let format: 'png' | 'jpeg' | null = null;
|
||||||
// options.type takes precedence over inferring the type from options.path
|
// options.type takes precedence over inferring the type from options.path
|
||||||
// because it may be a 0-length file with no extension created beforehand (i.e. as a temp file).
|
// because it may be a 0-length file with no extension created beforehand (i.e. as a temp file).
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Size, Point, Rect, TimeoutOptions } from '../common/types';
|
import { Size, Point, TimeoutOptions } from '../common/types';
|
||||||
export { Size, Point, Rect, Quad, URLMatch, TimeoutOptions } from '../common/types';
|
export { Size, Point, Rect, Quad, URLMatch, TimeoutOptions } from '../common/types';
|
||||||
|
|
||||||
export type StrictOptions = {
|
export type StrictOptions = {
|
||||||
@ -47,18 +47,6 @@ export type PointerActionWaitOptions = TimeoutOptions & ForceOptions & StrictOpt
|
|||||||
trial?: boolean;
|
trial?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ElementScreenshotOptions = TimeoutOptions & {
|
|
||||||
type?: 'png' | 'jpeg',
|
|
||||||
quality?: number,
|
|
||||||
omitBackground?: boolean,
|
|
||||||
disableAnimations?: boolean,
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ScreenshotOptions = ElementScreenshotOptions & {
|
|
||||||
fullPage?: boolean,
|
|
||||||
clip?: Rect,
|
|
||||||
};
|
|
||||||
|
|
||||||
export type PageScreencastOptions = {
|
export type PageScreencastOptions = {
|
||||||
width: number,
|
width: number,
|
||||||
height: number,
|
height: number,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user