fix: add new line before sourceURL (#29199)
Reference https://github.com/microsoft/playwright/issues/29116
This commit is contained in:
parent
ad6e40538a
commit
13550b7329
|
|
@ -43,8 +43,12 @@ export async function evaluationScript(fun: Function | string | { path?: string,
|
||||||
if (fun.path !== undefined) {
|
if (fun.path !== undefined) {
|
||||||
let source = await fs.promises.readFile(fun.path, 'utf8');
|
let source = await fs.promises.readFile(fun.path, 'utf8');
|
||||||
if (addSourceUrl)
|
if (addSourceUrl)
|
||||||
source += '\n//# sourceURL=' + fun.path.replace(/\n/g, '');
|
source = addSourceUrlToScript(source, fun.path);
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
throw new Error('Either path or content property must be present');
|
throw new Error('Either path or content property must be present');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function addSourceUrlToScript(source: string, path: string): string {
|
||||||
|
return `${source}\n//# sourceURL=${path.replace(/\n/g, '')}`;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import { kLifecycleEvents } from './types';
|
||||||
import { urlMatches } from '../utils/network';
|
import { urlMatches } from '../utils/network';
|
||||||
import type * as api from '../../types/types';
|
import type * as api from '../../types/types';
|
||||||
import type * as structs from '../../types/structs';
|
import type * as structs from '../../types/structs';
|
||||||
|
import { addSourceUrlToScript } from './clientHelper';
|
||||||
|
|
||||||
export type WaitForNavigationOptions = {
|
export type WaitForNavigationOptions = {
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
|
|
@ -266,7 +267,7 @@ export class Frame extends ChannelOwner<channels.FrameChannel> implements api.Fr
|
||||||
const copy = { ...options };
|
const copy = { ...options };
|
||||||
if (copy.path) {
|
if (copy.path) {
|
||||||
copy.content = (await fs.promises.readFile(copy.path)).toString();
|
copy.content = (await fs.promises.readFile(copy.path)).toString();
|
||||||
copy.content += '//# sourceURL=' + copy.path.replace(/\n/g, '');
|
copy.content = addSourceUrlToScript(copy.content, copy.path);
|
||||||
}
|
}
|
||||||
return ElementHandle.from((await this._channel.addScriptTag({ ...copy })).element);
|
return ElementHandle.from((await this._channel.addScriptTag({ ...copy })).element);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue