mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
feat: nicer error message for page.addScriptTag (#1754)
This commit is contained in:
parent
8536fa885e
commit
a7572c7f09
@ -135,13 +135,13 @@ export class FFExecutionContext implements js.ExecutionContextDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
function checkException(exceptionDetails?: any) {
|
||||
if (exceptionDetails) {
|
||||
if (exceptionDetails.value)
|
||||
throw new Error('Evaluation failed: ' + JSON.stringify(exceptionDetails.value));
|
||||
else
|
||||
throw new Error('Evaluation failed: ' + exceptionDetails.text + '\n' + exceptionDetails.stack);
|
||||
}
|
||||
function checkException(exceptionDetails?: Protocol.Runtime.ExceptionDetails) {
|
||||
if (!exceptionDetails)
|
||||
return;
|
||||
if (exceptionDetails.value)
|
||||
throw new Error('Evaluation failed: ' + JSON.stringify(exceptionDetails.value));
|
||||
else
|
||||
throw new Error('Evaluation failed: ' + exceptionDetails.text + '\n' + exceptionDetails.stack);
|
||||
}
|
||||
|
||||
export function deserializeValue({unserializableValue, value}: Protocol.Runtime.RemoteObject) {
|
||||
|
@ -580,7 +580,7 @@ export class Frame {
|
||||
script.type = options.type;
|
||||
const promise = new Promise((res, rej) => {
|
||||
script.onload = res;
|
||||
script.onerror = rej;
|
||||
script.onerror = e => rej(typeof e === 'string' ? new Error(e) : new Error(`Failed to load script at ${script.src}`));
|
||||
});
|
||||
document.head.appendChild(script);
|
||||
await promise;
|
||||
|
@ -654,6 +654,12 @@ describe('Page.addScriptTag', function() {
|
||||
await page.addScriptTag({ url: server.CROSS_PROCESS_PREFIX + '/injectedfile.js' }).catch(e => error = e);
|
||||
expect(error).toBeTruthy();
|
||||
});
|
||||
it('should throw a nice error when the request fails', async({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const url = server.PREFIX + '/this_does_not_exist.js';
|
||||
const error = await page.addScriptTag({url}).catch(e => e);
|
||||
expect(error.message).toContain(url);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Page.addStyleTag', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user