MCPcopy Create free account
hub / github.com/angular/angular / errorFilenameHandler

Function errorFilenameHandler

adev/src/app/editor/error-filename-handler.ts:11–36  ·  view source on GitHub ↗
(parentOrigin: string)

Source from the content-addressed store, hash-verified

9import {WebContainer} from '@webcontainer/api';
10
11function errorFilenameHandler(parentOrigin: string) {
12 const originalFetch = window.fetch;
13 window.fetch = async (input, init) => {
14 const url = input.toString();
15 if (url.includes('__open-in-editor')) {
16 const params = new URLSearchParams(url.split('?')[1]);
17 const file = params.get('file');
18 if (file) {
19 const [filepath, line, column] = file.split(':');
20 window.parent.postMessage(
21 {
22 type: 'openFileAtLocation',
23 file: filepath,
24 line: parseInt(line, 10),
25 character: parseInt(column, 10),
26 },
27 // Only expose the message to the parent origin that embedded the
28 // preview, instead of broadcasting it to any origin via `'*'`.
29 parentOrigin,
30 );
31 }
32 return new Response(null, {status: 200});
33 }
34 return originalFetch(input, init);
35 };
36}
37
38export async function setupErrorFilenameHandler(webContainer: WebContainer): Promise<void> {
39 // The handler below is serialized and executed inside the preview iframe,

Callers

nothing calls this directly

Calls 3

toStringMethod · 0.65
getMethod · 0.65
postMessageMethod · 0.45

Tested by

no test coverage detected