fix: implement log scale back-off for screenshots (#12504)
References https://github.com/microsoft/playwright/issues/12441
This commit is contained in:
parent
4953fc4845
commit
6dac01aec7
|
|
@ -1058,7 +1058,7 @@ export class Frame extends SdkObject {
|
|||
});
|
||||
}
|
||||
|
||||
async rafrafTimeoutScreenshotElementWithProgress(progress: Progress, selector: string, timeout: number, options: ScreenshotOptions): Promise<Buffer|undefined> {
|
||||
async rafrafTimeoutScreenshotElementWithProgress(progress: Progress, selector: string, timeout: number, options: ScreenshotOptions): Promise<Buffer> {
|
||||
return await this._retryWithProgressIfNotConnected(progress, selector, true /* strict */, async handle => {
|
||||
await handle._frame.rafrafTimeout(timeout);
|
||||
return await this._page._screenshotter.screenshotElement(progress, handle, options);
|
||||
|
|
|
|||
|
|
@ -461,21 +461,21 @@ export class Page extends SdkObject {
|
|||
return controller.run(async progress => {
|
||||
let actual: Buffer | undefined;
|
||||
let previous: Buffer | undefined;
|
||||
let screenshotTimeout = 0;
|
||||
const pollIntervals = [0, 100, 250, 500];
|
||||
while (true) {
|
||||
progress.throwIfAborted();
|
||||
if (this.isClosed())
|
||||
throw new Error('The page has closed');
|
||||
let comparatorResult: ComparatorResult | undefined;
|
||||
const screenshotTimeout = pollIntervals.shift() || 1000;
|
||||
if (isGeneratingNewScreenshot) {
|
||||
previous = actual;
|
||||
actual = await rafrafScreenshot(progress, screenshotTimeout);
|
||||
actual = await rafrafScreenshot(progress, screenshotTimeout).catch(e => undefined);
|
||||
comparatorResult = actual && previous ? comparator(actual, previous, options.comparatorOptions) : undefined;
|
||||
} else {
|
||||
actual = await rafrafScreenshot(progress, screenshotTimeout);
|
||||
actual = await rafrafScreenshot(progress, screenshotTimeout).catch(e => undefined);
|
||||
comparatorResult = actual ? comparator(actual, options.expected!, options.comparatorOptions) : undefined;
|
||||
}
|
||||
screenshotTimeout = 150;
|
||||
if (comparatorResult !== undefined && !!comparatorResult === !!options.isNot)
|
||||
break;
|
||||
if (comparatorResult)
|
||||
|
|
|
|||
Loading…
Reference in a new issue