mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-17 15:24:40 +01:00
Browser favicons: better error handling & data URL support (#305244)
This commit is contained in:
@@ -169,6 +169,9 @@ export class BrowserView extends Disposable implements ICDPTarget {
|
||||
for (const url of favicons) {
|
||||
if (!this._faviconRequestCache.has(url)) {
|
||||
this._faviconRequestCache.set(url, (async () => {
|
||||
if (url.startsWith('data:image/')) {
|
||||
return url;
|
||||
}
|
||||
const response = await webContents.session.fetch(url, {
|
||||
cache: 'force-cache'
|
||||
});
|
||||
@@ -176,6 +179,9 @@ export class BrowserView extends Disposable implements ICDPTarget {
|
||||
throw new Error(`Failed to fetch favicon: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
const type = await response.headers.get('content-type');
|
||||
if (!type?.startsWith('image/')) {
|
||||
throw new Error(`Favicon is not an image: ${type}`);
|
||||
}
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return `data:${type};base64,${Buffer.from(buffer).toString('base64')}`;
|
||||
|
||||
Reference in New Issue
Block a user