Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds cacheBustingEnabled setting to simple browser #205106

Closed
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
6 changes: 6 additions & 0 deletions extensions/simple-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
"default": true,
"title": "Focus Lock Indicator Enabled",
"description": "%configuration.focusLockIndicator.enabled.description%"
},
"simpleBrowser.cacheBusting.enabled": {
"type": "boolean",
"default": true,
"title": "Cache Busting Enabled",
"description": "%configuration.cacheBusting.enabled.description%"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion extensions/simple-browser/package.nls.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"displayName": "Simple Browser",
"description": "A very basic built-in webview for displaying web content.",
"configuration.focusLockIndicator.enabled.description": "Enable/disable the floating indicator that shows when focused in the simple browser."
"configuration.focusLockIndicator.enabled.description": "Enable/disable the floating indicator that shows when focused in the simple browser.",
"configuration.cacheBusting.enabled.description": "Enable/disable the cacheBusting behavior that appends vscodeBrowserReqId to all requests."
}
18 changes: 15 additions & 3 deletions extensions/simple-browser/preview-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ window.addEventListener('message', e => {
toggleFocusLockIndicatorEnabled(e.data.enabled);
break;
}
case 'didChangeCaheBustingEnabled':
{
toggleCacheBustingEnabled(e.data.enabled);
break;
}
}
});

Expand Down Expand Up @@ -88,14 +93,17 @@ onceDocumentLoaded(() => {
input.value = settings.url;

toggleFocusLockIndicatorEnabled(settings.focusLockIndicatorEnabled);
toggleCacheBustingEnabled(settings.cacheBustingEnabled);

function navigateTo(rawUrl: string): void {
try {
const url = new URL(rawUrl);

// Try to bust the cache for the iframe
// There does not appear to be any way to reliably do this except modifying the url
url.searchParams.append('vscodeBrowserReqId', Date.now().toString());
if (settings.cacheBustingEnabled) {
// Try to bust the cache for the iframe
// There does not appear to be any way to reliably do this except modifying the url
url.searchParams.append('vscodeBrowserReqId', Date.now().toString());
}

iframe.src = url.toString();
} catch {
Expand All @@ -110,3 +118,7 @@ function toggleFocusLockIndicatorEnabled(enabled: boolean) {
document.body.classList.toggle('enable-focus-lock-indicator', enabled);
}

function toggleCacheBustingEnabled(enabled: boolean) {
document.body.classList.toggle('enable-cache-busting-indicator', enabled);
}

11 changes: 10 additions & 1 deletion extensions/simple-browser/src/simpleBrowserView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ export class SimpleBrowserView extends Disposable {
focusLockEnabled: configuration.get<boolean>('focusLockIndicator.enabled', true)
});
}

if (e.affectsConfiguration('simpleBrowser.cacheBusting.enabled')) {
const configuration = vscode.workspace.getConfiguration('simpleBrowser');
this._webviewPanel.webview.postMessage({
type: 'didChangeCacheBustingEnabled',
cacheBustingEnabled: configuration.get<boolean>('cacheBusting.enabled', true)
});
}
}));

this.show(url);
Expand Down Expand Up @@ -133,7 +141,8 @@ export class SimpleBrowserView extends Disposable {

<meta id="simple-browser-settings" data-settings="${escapeAttribute(JSON.stringify({
url: url,
focusLockEnabled: configuration.get<boolean>('focusLockIndicator.enabled', true)
focusLockEnabled: configuration.get<boolean>('focusLockIndicator.enabled', true),
cacheBustingEnabled: configuration.get<boolean>('cacheBusting.enabled', true)
}))}">

<link rel="stylesheet" type="text/css" href="${mainCss}">
Expand Down