()
| 9 | import {WebContainer} from '@webcontainer/api'; |
| 10 | |
| 11 | function errorFilenameHandler() { |
| 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 | '*', |
| 28 | ); |
| 29 | } |
| 30 | return new Response(null, {status: 200}); |
| 31 | } |
| 32 | return originalFetch(input, init); |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | export async function setupErrorFilenameHandler(webContainer: WebContainer): Promise<void> { |
| 37 | await webContainer.setPreviewScript(`(${errorFilenameHandler.toString()})()`); |
nothing calls this directly
no test coverage detected
searching dependent graphs…