mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
refactor: remove deferred from addScriptTag (#12165)
This commit is contained in:
parent
c9ad6b48c4
commit
957cb8ee6c
@ -841,42 +841,37 @@ export abstract class Frame extends EventEmitter<FrameEvents> {
|
|||||||
|
|
||||||
return await this.mainRealm().transferHandle(
|
return await this.mainRealm().transferHandle(
|
||||||
await this.isolatedRealm().evaluateHandle(
|
await this.isolatedRealm().evaluateHandle(
|
||||||
async ({Deferred}, {url, id, type, content}) => {
|
async ({url, id, type, content}) => {
|
||||||
const deferred = Deferred.create<void>();
|
return await new Promise<HTMLScriptElement>((resolve, reject) => {
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.type = type;
|
script.type = type;
|
||||||
script.text = content;
|
script.text = content;
|
||||||
if (url) {
|
|
||||||
script.src = url;
|
|
||||||
script.addEventListener(
|
|
||||||
'load',
|
|
||||||
() => {
|
|
||||||
return deferred.resolve();
|
|
||||||
},
|
|
||||||
{once: true}
|
|
||||||
);
|
|
||||||
script.addEventListener(
|
script.addEventListener(
|
||||||
'error',
|
'error',
|
||||||
event => {
|
event => {
|
||||||
deferred.reject(
|
reject(new Error(event.message ?? 'Could not load script'));
|
||||||
new Error(event.message ?? 'Could not load script')
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
{once: true}
|
{once: true}
|
||||||
);
|
);
|
||||||
} else {
|
if (id) {
|
||||||
deferred.resolve();
|
script.id = id;
|
||||||
}
|
}
|
||||||
if (id) {
|
if (url) {
|
||||||
script.id = id;
|
script.src = url;
|
||||||
}
|
script.addEventListener(
|
||||||
document.head.appendChild(script);
|
'load',
|
||||||
await deferred.valueOrThrow();
|
() => {
|
||||||
return script;
|
resolve(script);
|
||||||
|
},
|
||||||
|
{once: true}
|
||||||
|
);
|
||||||
|
document.head.appendChild(script);
|
||||||
|
} else {
|
||||||
|
document.head.appendChild(script);
|
||||||
|
resolve(script);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
LazyArg.create(context => {
|
|
||||||
return context.puppeteerUtil;
|
|
||||||
}),
|
|
||||||
{...options, type, content}
|
{...options, type, content}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -649,7 +649,7 @@
|
|||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["webDriverBiDi"],
|
||||||
"expectations": ["FAIL"],
|
"expectations": ["FAIL"],
|
||||||
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
|
"comment": "See https://github.com/puppeteer/puppeteer/issues/4840"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[page.spec] Page Page.addStyleTag should throw when added with content to the CSP page",
|
"testIdPattern": "[page.spec] Page Page.addStyleTag should throw when added with content to the CSP page",
|
||||||
@ -3010,7 +3010,7 @@
|
|||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["cdp", "chrome"],
|
"parameters": ["cdp", "chrome"],
|
||||||
"expectations": ["SKIP"],
|
"expectations": ["SKIP"],
|
||||||
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
|
"comment": "See https://github.com/puppeteer/puppeteer/issues/4840"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[page.spec] Page Page.addScriptTag should throw when added with content to the CSP page",
|
"testIdPattern": "[page.spec] Page Page.addScriptTag should throw when added with content to the CSP page",
|
||||||
|
Loading…
Reference in New Issue
Block a user