Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-devtools-mute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: silently 404 Chrome DevTools workspaces request in dev and preview
6 changes: 5 additions & 1 deletion packages/kit/src/exports/vite/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { SVELTE_KIT_ASSETS } from '../../../constants.js';
import * as sync from '../../../core/sync/sync.js';
import { get_mime_lookup, runtime_base } from '../../../core/utils.js';
import { compact } from '../../../utils/array.js';
import { not_found } from '../utils.js';
import { is_chrome_devtools_request, not_found } from '../utils.js';
import { SCHEME } from '../../../utils/url.js';
import { check_feature } from '../../../utils/features.js';
import { escape_html } from '../../../utils/escape.js';
Expand Down Expand Up @@ -467,6 +467,10 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
return;
}

if (is_chrome_devtools_request(decoded, res)) {
return;
}

if (!decoded.startsWith(svelte_config.kit.paths.base)) {
return not_found(req, res, svelte_config.kit.paths.base);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/kit/src/exports/vite/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { loadEnv, normalizePath } from 'vite';
import { createReadableStream, getRequest, setResponse } from '../../../exports/node/index.js';
import { installPolyfills } from '../../../exports/node/polyfills.js';
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
import { not_found } from '../utils.js';
import { is_chrome_devtools_request, not_found } from '../utils.js';

/** @typedef {import('http').IncomingMessage} Req */
/** @typedef {import('http').ServerResponse} Res */
Expand Down Expand Up @@ -102,6 +102,10 @@ export async function preview(vite, vite_config, svelte_config) {
return;
}

if (is_chrome_devtools_request(pathname, res)) {
return;
}

if (pathname.startsWith(base)) {
next();
} else {
Expand Down
18 changes: 18 additions & 0 deletions packages/kit/src/exports/vite/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ export function get_env(env_config, mode) {
};
}

/**
* Silently respond with 404 for Chrome DevTools workspaces request.
* Chrome always requests this at the root, regardless of base path.
* Users who want workspaces can install `vite-plugin-devtools-json`,
* which takes precedence as Vite plugin middleware runs first.
* @param {string} pathname
* @param {import('http').ServerResponse} res
* @returns {boolean} `true` if the request was handled
*/
export function is_chrome_devtools_request(pathname, res) {
if (pathname === '/.well-known/appspecific/com.chrome.devtools.json') {
res.writeHead(404);
res.end('not found');
return true;
}
return false;
}

/**
* @param {import('http').IncomingMessage} req
* @param {import('http').ServerResponse} res
Expand Down
17 changes: 0 additions & 17 deletions packages/kit/src/runtime/server/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ const page_methods = new Set(['GET', 'HEAD', 'POST']);

const allowed_page_methods = new Set(['GET', 'HEAD', 'OPTIONS']);

let warned_on_devtools_json_request = false;

export const respond = propagate_context(internal_respond);

/**
Expand Down Expand Up @@ -676,21 +674,6 @@ export async function internal_respond(request, options, manifest, state) {
// if this request came direct from the user, rather than
// via our own `fetch`, render a 404 page
if (state.depth === 0) {
// In local development, Chrome requests this file for its 'automatic workspace folders' feature,
// causing console spam. If users want to serve this file they can install
// https://svelte.dev/docs/cli/devtools-json
if (DEV && event.url.pathname === '/.well-known/appspecific/com.chrome.devtools.json') {
if (!warned_on_devtools_json_request) {
console.log(
`\nGoogle Chrome is requesting ${event.url.pathname} to automatically configure devtools project settings. To learn why, and how to prevent this message, see https://svelte.dev/docs/cli/devtools-json\n`
);

warned_on_devtools_json_request = true;
}

return new Response(undefined, { status: 404 });
}

return await respond_with_error({
event,
event_state,
Expand Down
6 changes: 6 additions & 0 deletions packages/kit/test/apps/basics/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,12 @@ test.describe('Static files', () => {
expect(await response.text()).toBe('hello');
});
}

test('returns 404 for Chrome DevTools workspaces request', async ({ request }) => {
const response = await request.get('/.well-known/appspecific/com.chrome.devtools.json');
expect(response.status()).toBe(404);
expect(await response.text()).toBe('not found');
});
});

test.describe('setHeaders', () => {
Expand Down
Loading