code-server
code-server copied to clipboard
Markdown Preview is not working
Issue is similar to https://github.com/cdr/code-server/issues/296 The fix in this issue is not applicable to me I think since I'm not running behind nginx.
- Web Browser: Google Chrome
- Local OS: Windows 10
- Remote OS: Ubuntu 20.04
Steps to Reproduce
- Open any
md
file. - Try previewing the document.
Nothing in the code-server logs, But on dev tools,
Uncaught (in promise) Error: Service Workers are not enabled. Webviews will not work. Try disabling private/incognito mode.
at main.js:115
at new Promise (<anonymous>)
at main.js:115
I'm not accesing it in incognito mode.
@benjcabalona1029 you need to enable service workers in order for the markdown preview to work. Are you serving code-server via HTTPS?
@jsjoeio Thank yor for your comment. How do i enable the service workers? No, I'm not serving it in https.
No, I'm not serving it in https
There's your issue. You'll need to serve it via HTTPS and that will allow your browser to enable service workers automatically I believe.
I'm going to close this since this is related to your environment but feel free to open a Discussion if you need more help or have a question about enabling HTTPS. See the docs here for more info.
Hi @jsjoeio I tried serving it with the --link
for it to be served in HTTPS, however the preview is still not working.
I get a new error,
ERR [UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//"): Error: [UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")
at b (https://benjcabalona-benjcabalona1029.cdr.co/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench/workbench.web.api.js:70:77397)
at new p (https://benjcabalona-benjcabalona1029.cdr.co/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench/workbench.web.api.js:70:78038)
at new m (https://benjcabalona-benjcabalona1029.cdr.co/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench/workbench.web.api.js:70:79686)
at Function.from (https://benjcabalona-benjcabalona1029.cdr.co/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench/workbench.web.api.js:70:79103)
at https://benjcabalona-benjcabalona1029.cdr.co/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench/workbench.web.api.js:1271:14766
at String.replace (<anonymous>)
at _.rewriteVsCodeResourceUrls (https://benjcabalona-benjcabalona1029.cdr.co/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench/workbench.web.api.js:1271:14654)
at _.set html [as html] (https://benjcabalona-benjcabalona1029.cdr.co/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench/workbench.web.api.js:1271:14307)
at https://benjcabalona-benjcabalona1029.cdr.co/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench/workbench.web.api.js:1226:30501
at b.withWebview (https://benjcabalona-benjcabalona1029.cdr.co/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/vendor/modules/code-oss-dev/out/vs/workbench/workbench.web.api.js:1226:31874)
Uhh...I have yet to see this error 🤔 @code-asher any ideas?
Hmm quite odd indeed. The only way I can think of for the authority to be missing is if the host header is missing but we have used link successfully before so I am not sure.
There have been changes to the remote authority in the latest code so it is possible it will be fixed there.
Okay, I'll try to update it once we have a new release. Can we reopen this issue? @jsjoeio
Good call! You got it
Might be unrelated but I have seen Issues like that while using private/incognito mode.
For some odd reasons serverice workers won't start in incognito...
Edit: this seems only be true for firefox
For some odd reasons serverice workers won't start in incognito...
I believe service workers are disabled in incognito in Firefox (IIRC)
Markdown preview is also not working for me since upgrading to 4.0.1 it seems (from 3.x). I use SSH forwarding, and in the Chrome "Application" tab I see two service workers are green with status "activated and is running." Triggering markdown preview results in no new system logs or console logs, just shows "Activating Extensions..." then nothing happens.
Console log
INFO [Service Worker] registered
webWorkerExtensionHost.ts:211 GET http://localhost:8081/static/stable/out/vs/workbench/services/extensions/worker/httpWebWorkerExtensionHostIframe.html?&vscodeWebWorkerExtHostId=f5c546d0-a5ec-4bbe-8289-7c3da99f2316 404 (Not Found)
_startInsideIframe @ webWorkerExtensionHost.ts:211
start @ webWorkerExtensionHost.ts:138
Qr @ extensionHostManager.ts:124
_createInstance @ instantiationService.ts:110
createInstance @ instantiationService.ts:76
g @ extensionHostManager.ts:57
(anonymous) @ abstractExtensionService.ts:625
_startExtensionHosts @ abstractExtensionService.ts:624
_initialize @ abstractExtensionService.ts:521
(anonymous) @ extensionService.ts:79
Promise.then (async)
Hl @ extensionService.ts:77
_createInstance @ instantiationService.ts:110
_createServiceInstance @ instantiationService.ts:230
_createServiceInstanceWithOwner @ instantiationService.ts:219
_createAndCacheServiceInstance @ instantiationService.ts:208
_safeCreateAndCacheServiceInstance @ instantiationService.ts:151
_getOrCreateServiceInstance @ instantiationService.ts:135
_createInstance @ instantiationService.ts:88
createInstance @ instantiationService.ts:76
acquireInstantiationService @ configurationService.ts:457
(anonymous) @ workbench.ts:212
invokeFunction @ instantiationService.ts:61
initServices @ workbench.ts:206
startup @ workbench.ts:138
open @ web.main.ts:103
abstractExtensionService.ts:927 [ms-python.python]: Cannot register 'python.pythonPath'. This property is already registered.
_logMessageInConsole @ abstractExtensionService.ts:927
_handleExtensionPointMessage @ abstractExtensionService.ts:878
X @ abstractExtensionService.ts:852
_msg @ extensionsRegistry.ts:37
warn @ extensionsRegistry.ts:50
g @ configurationExtensionPoint.ts:237
h @ configurationExtensionPoint.ts:212
(anonymous) @ configurationExtensionPoint.ts:283
_handle @ extensionsRegistry.ts:143
acceptUsers @ extensionsRegistry.ts:134
_handleExtensionPoint @ abstractExtensionService.ts:912
_doHandleExtensionPoints @ abstractExtensionService.ts:858
_scanAndHandleExtensions @ extensionService.ts:223
await in _scanAndHandleExtensions (async)
_initialize @ abstractExtensionService.ts:525
await in _initialize (async)
(anonymous) @ extensionService.ts:79
Promise.then (async)
Hl @ extensionService.ts:77
_createInstance @ instantiationService.ts:110
_createServiceInstance @ instantiationService.ts:230
_createServiceInstanceWithOwner @ instantiationService.ts:219
_createAndCacheServiceInstance @ instantiationService.ts:208
_safeCreateAndCacheServiceInstance @ instantiationService.ts:151
_getOrCreateServiceInstance @ instantiationService.ts:135
_createInstance @ instantiationService.ts:88
createInstance @ instantiationService.ts:76
acquireInstantiationService @ configurationService.ts:457
(anonymous) @ workbench.ts:212
invokeFunction @ instantiationService.ts:61
initServices @ workbench.ts:206
startup @ workbench.ts:138
open @ web.main.ts:103
await in open (async)
fe @ web.main.ts:413
n @ workbench.web.api.ts:664
(anonymous) @ workbench.ts:565
(anonymous) @ workbench.ts:603
i._invokeFactory @ loader.js:1185
i.complete @ loader.js:1195
i._onModuleComplete @ loader.js:1821
i._onModuleComplete @ loader.js:1833
i._resolve @ loader.js:1781
i.defineModule @ loader.js:1424
o @ loader.js:1709
_ @ loader.js:2208
i._invokeFactory @ loader.js:1185
i.complete @ loader.js:1195
i._onModuleComplete @ loader.js:1821
i._onModuleComplete @ loader.js:1833
i._resolve @ loader.js:1781
i.defineModule @ loader.js:1424
v @ loader.js:1871
(anonymous) @ workbench.nls.js:7
abstractExtensionService.ts:927 [ms-python.python]: Cannot register 'python.venvPath'. This property is already registered.
_logMessageInConsole @ abstractExtensionService.ts:927
_handleExtensionPointMessage @ abstractExtensionService.ts:878
X @ abstractExtensionService.ts:852
_msg @ extensionsRegistry.ts:37
warn @ extensionsRegistry.ts:50
g @ configurationExtensionPoint.ts:237
h @ configurationExtensionPoint.ts:212
(anonymous) @ configurationExtensionPoint.ts:283
_handle @ extensionsRegistry.ts:143
acceptUsers @ extensionsRegistry.ts:134
_handleExtensionPoint @ abstractExtensionService.ts:912
_doHandleExtensionPoints @ abstractExtensionService.ts:858
_scanAndHandleExtensions @ extensionService.ts:223
await in _scanAndHandleExtensions (async)
_initialize @ abstractExtensionService.ts:525
await in _initialize (async)
(anonymous) @ extensionService.ts:79
Promise.then (async)
Hl @ extensionService.ts:77
_createInstance @ instantiationService.ts:110
_createServiceInstance @ instantiationService.ts:230
_createServiceInstanceWithOwner @ instantiationService.ts:219
_createAndCacheServiceInstance @ instantiationService.ts:208
_safeCreateAndCacheServiceInstance @ instantiationService.ts:151
_getOrCreateServiceInstance @ instantiationService.ts:135
_createInstance @ instantiationService.ts:88
createInstance @ instantiationService.ts:76
acquireInstantiationService @ configurationService.ts:457
(anonymous) @ workbench.ts:212
invokeFunction @ instantiationService.ts:61
initServices @ workbench.ts:206
startup @ workbench.ts:138
open @ web.main.ts:103
await in open (async)
fe @ web.main.ts:413
n @ workbench.web.api.ts:664
(anonymous) @ workbench.ts:565
(anonymous) @ workbench.ts:603
i._invokeFactory @ loader.js:1185
i.complete @ loader.js:1195
i._onModuleComplete @ loader.js:1821
i._onModuleComplete @ loader.js:1833
i._resolve @ loader.js:1781
i.defineModule @ loader.js:1424
o @ loader.js:1709
_ @ loader.js:2208
i._invokeFactory @ loader.js:1185
i.complete @ loader.js:1195
i._onModuleComplete @ loader.js:1821
i._onModuleComplete @ loader.js:1833
i._resolve @ loader.js:1781
i.defineModule @ loader.js:1424
v @ loader.js:1871
(anonymous) @ workbench.nls.js:7
mime.ts:64 Overwriting extension <<.hbs>> to now point to mime <<text/x-handlebars>>
(anonymous) @ mime.ts:64
v @ mime.ts:58
_mergeLanguage @ languagesRegistry.ts:191
_registerLanguage @ languagesRegistry.ts:165
_registerLanguages @ languagesRegistry.ts:120
_initializeFromRegistry @ languagesRegistry.ts:114
(anonymous) @ languagesRegistry.ts:96
fire @ event.ts:577
setDynamicLanguages @ modesRegistry.ts:50
(anonymous) @ workbenchModeService.ts:139
_handle @ extensionsRegistry.ts:143
acceptUsers @ extensionsRegistry.ts:134
_handleExtensionPoint @ abstractExtensionService.ts:912
_doHandleExtensionPoints @ abstractExtensionService.ts:858
_scanAndHandleExtensions @ extensionService.ts:223
await in _scanAndHandleExtensions (async)
_initialize @ abstractExtensionService.ts:525
await in _initialize (async)
(anonymous) @ extensionService.ts:79
Promise.then (async)
Hl @ extensionService.ts:77
_createInstance @ instantiationService.ts:110
_createServiceInstance @ instantiationService.ts:230
_createServiceInstanceWithOwner @ instantiationService.ts:219
_createAndCacheServiceInstance @ instantiationService.ts:208
_safeCreateAndCacheServiceInstance @ instantiationService.ts:151
_getOrCreateServiceInstance @ instantiationService.ts:135
_createInstance @ instantiationService.ts:88
createInstance @ instantiationService.ts:76
acquireInstantiationService @ configurationService.ts:457
(anonymous) @ workbench.ts:212
invokeFunction @ instantiationService.ts:61
initServices @ workbench.ts:206
startup @ workbench.ts:138
open @ web.main.ts:103
await in open (async)
fe @ web.main.ts:413
n @ workbench.web.api.ts:664
(anonymous) @ workbench.ts:565
(anonymous) @ workbench.ts:603
i._invokeFactory @ loader.js:1185
i.complete @ loader.js:1195
i._onModuleComplete @ loader.js:1821
i._onModuleComplete @ loader.js:1833
i._resolve @ loader.js:1781
i.defineModule @ loader.js:1424
o @ loader.js:1709
_ @ loader.js:2208
i._invokeFactory @ loader.js:1185
i.complete @ loader.js:1195
i._onModuleComplete @ loader.js:1821
i._onModuleComplete @ loader.js:1833
i._resolve @ loader.js:1781
i.defineModule @ loader.js:1424
v @ loader.js:1871
(anonymous) @ workbench.nls.js:7
mime.ts:64 Overwriting extension <<.handlebars>> to now point to mime <<text/x-handlebars>>
(anonymous) @ mime.ts:64
v @ mime.ts:58
_mergeLanguage @ languagesRegistry.ts:191
_registerLanguage @ languagesRegistry.ts:165
_registerLanguages @ languagesRegistry.ts:120
_initializeFromRegistry @ languagesRegistry.ts:114
(anonymous) @ languagesRegistry.ts:96
fire @ event.ts:577
setDynamicLanguages @ modesRegistry.ts:50
(anonymous) @ workbenchModeService.ts:139
_handle @ extensionsRegistry.ts:143
acceptUsers @ extensionsRegistry.ts:134
_handleExtensionPoint @ abstractExtensionService.ts:912
_doHandleExtensionPoints @ abstractExtensionService.ts:858
_scanAndHandleExtensions @ extensionService.ts:223
await in _scanAndHandleExtensions (async)
_initialize @ abstractExtensionService.ts:525
await in _initialize (async)
(anonymous) @ extensionService.ts:79
Promise.then (async)
Hl @ extensionService.ts:77
_createInstance @ instantiationService.ts:110
_createServiceInstance @ instantiationService.ts:230
_createServiceInstanceWithOwner @ instantiationService.ts:219
_createAndCacheServiceInstance @ instantiationService.ts:208
_safeCreateAndCacheServiceInstance @ instantiationService.ts:151
_getOrCreateServiceInstance @ instantiationService.ts:135
_createInstance @ instantiationService.ts:88
createInstance @ instantiationService.ts:76
acquireInstantiationService @ configurationService.ts:457
(anonymous) @ workbench.ts:212
invokeFunction @ instantiationService.ts:61
initServices @ workbench.ts:206
startup @ workbench.ts:138
open @ web.main.ts:103
await in open (async)
fe @ web.main.ts:413
n @ workbench.web.api.ts:664
(anonymous) @ workbench.ts:565
(anonymous) @ workbench.ts:603
i._invokeFactory @ loader.js:1185
i.complete @ loader.js:1195
i._onModuleComplete @ loader.js:1821
i._onModuleComplete @ loader.js:1833
i._resolve @ loader.js:1781
i.defineModule @ loader.js:1424
o @ loader.js:1709
_ @ loader.js:2208
i._invokeFactory @ loader.js:1185
i.complete @ loader.js:1195
i._onModuleComplete @ loader.js:1821
i._onModuleComplete @ loader.js:1833
i._resolve @ loader.js:1781
i.defineModule @ loader.js:1424
v @ loader.js:1871
(anonymous) @ workbench.nls.js:7
I @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
_doInvokeHandler @ rpcProtocol.ts:472
_invokeHandler @ rpcProtocol.ts:457
_receiveRequest @ rpcProtocol.ts:373
_receiveOneMessage @ rpcProtocol.ts:295
(anonymous) @ rpcProtocol.ts:160
fire @ event.ts:577
fire @ ipc.net.ts:511
_receiveMessage @ ipc.net.ts:869
(anonymous) @ ipc.net.ts:708
fire @ event.ts:577
acceptChunk @ ipc.net.ts:284
(anonymous) @ ipc.net.ts:245
(anonymous) @ browserSocketFactory.ts:197
fire @ event.ts:577
C._fileReader.onload @ browserSocketFactory.ts:81
webWorkerExtensionHost.ts:184 The Web Worker Extension Host did not start in 60s, that might be a problem.
Not sure if related or a new issue.
When use http://127.0.0.1 or http://localhost code-server's markdown-preview-enhanced preview should worked fine, otherwise use http://ip markdown-preview-enhanced preview is not working.
VSCode markdown Plugin: shd101wyy.markdown-preview-enhanced Explorer: firefox or chrome CodeServer: v4.0.2
Chrome Console:
VM6:1 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'sha256-cb2sg39EJV8ABaSNFfWu/ou8o1xVXYK7jp90oZ9vpcg=' http: https:". Either the 'unsafe-inline' keyword, a hash ('sha256-4sNwvmWshEzqW5S25HVAak+QIUCkjYSbAaQ7Ieh/EDA='), or a nonce ('nonce-...') is required to enable inline execution.
t @ VM6:1
i @ VM6:1
a @ VM6:1
(anonymous) @ VM6:1
VM31 main.js:115 Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener')
at VM31 main.js:115
(anonymous) @ VM31 main.js:115
VM31 main.js:115 Uncaught (in promise) Error: Service Workers are not enabled. Webviews will not work. Try disabling private/incognito mode.
at VM31 main.js:115
at new Promise (<anonymous>)
at VM31 main.js:115
(anonymous) @ VM31 main.js:115
(anonymous) @ VM31 main.js:115
You need to be on HTTPS for it work
Thanks , but Markdown-preview still can't appear after using https, and the following prompt is 'Activating Extensions...', Chrome Console log : VM147:1 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval' 'sha256-HuyBNEnumn/Bw3njx2R0EXAv9HicWHLQQd9NJ9ruyrk=' 'sha256-hwmTfNWB8XRD349z+U9G9OefbQgy28G4Xs7WyYCCXgM=' 'sha256-yxwQ9j8YGPsfU554CNGiSCW08z5yqDVvuQmssjoPsm8=' 'sha256-cb2sg39EJV8ABaSNFfWu/ou8o1xVXYK7jp90oZ9vpcg='". Either the 'unsafe-inline' keyword, a hash ('sha256-4sNwvmWshEzqW5S25HVAak+QIUCkjYSbAaQ7Ieh/EDA='), or a nonce ('nonce-...') is required to enable inline execution.
t @ VM147:1 i @ VM147:1 a @ VM147:1 (anonymous) @ VM147:1 VM147:1 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'unsafe-eval' 'sha256-cb2sg39EJV8ABaSNFfWu/ou8o1xVXYK7jp90oZ9vpcg=' https:". Either the 'unsafe-inline' keyword, a hash ('sha256-4sNwvmWshEzqW5S25HVAak+QIUCkjYSbAaQ7Ieh/EDA='), or a nonce ('nonce-...') is required to enable inline execution.
@tlw-ray hmm I'm not sure what that could be. Your error message looks very odd. You're using 4.0.2? Can you try clearing your cache maybe?
It's working for me.

@jsjoeio, hi, I'm finding the cause of the problem.
case1: Start code-server-4.0.2 with out cert. (I only using this version server)
When accessing the server via http://127.0.0.1
or http://localhost
, typing navigator.serviceWorker
in the browser's console, return a ServiceWorkerContainer
object. At this point, markdown preview
is ok.
Accssing via http://ip
, such options return null. Of course, the markdown preview
is invalid. Explorer console log warnning (Https may be needed at this point):
main.js:400 Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener')
at main.js:400
(anonymous) @ main.js:400
main.js:204 Uncaught (in promise) Error: Service Workers are not enabled. Webviews will not work. Try disabling private/incognito mode.
at main.js:204
at new Promise (<anonymous>)
at main.js:202
case2: Start with cert and cert-key, and let explorer trust the self cert ROOTCA(https no warning in explorer).
Access via https://domain
, such options return the ServiceWorkerContainer
fine, when open markdown preview
a waiting prompt for Activating Service...
appears in the status bar in the lower left. But the preview panel(iframe) is always blank, browser console outputs the logs in gray(seen that it is communicating with the background, but I think this feature supposed to run inside the browser):
INFO [remote-connection][ExtensionHost][b984b…][reconnect] starting reconnecting loop. You can get more information with the trace log level.
log.ts:301 INFO [remote-connection][ExtensionHost][b984b…][reconnect] resolving connection...
log.ts:301 INFO [remote-connection][ExtensionHost][b984b…][reconnect] connecting to example.com:9070...
log.ts:301 INFO [remote-connection][ExtensionHost][b984b…][reconnect] reconnected!
Note the gray log~ Is this normal?
Although 4.0.2 fixed some http / https related issues for me it did not fix Markdown preview via http (and hostname).
Note the gray log~ Is this normal?
Ah maybe I'm slow, but what am I looking at here?
case2: Start with cert and cert-key, and let explorer trust the self cert ROOTCA(https no warning in explorer).
That looks like https://github.com/coder/code-server/issues/4773 which should be fixed in 4.0.3
Great~
Still not works for me
@Cleanairdreaming are you using HTTPS?
Hi @jsjoeio ,
I'm trying to build a react application with the code server as an iframe. The code server is served over HTTPS and when I tried to launch my react application in my local (http://localhost:3000), I don't see any issues. However, when I deploy my react application to a domain (http://my-app.com) that's when I'm getting the error that the OP posted and also a popup saying that
code-server is being accessed in an insecure context. Web views, the clipboard, and other functionality may not work as expected.
Also when I try to open the code server URL from the iframe to a new tab, I don't see this issue. Do I need to host my react application in HTTPS as well?
code-server: v4.3.0 Code: 1.65.2 Commit: Unknown Date: 2022-04-14T21:04:05.402Z Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Can you deploy it to HTTPS? I believe many services offer this for free. Other than that, there isn't much we can do since this is a browser limitation
Maybe #5338 is related?
Can you deploy it to HTTPS? I believe many services offer this for free. Other than that, there isn't much we can do since this is a browser limitation
I deployed it in HTTPS and it works as expected. Thanks @jsjoeio
awesome! i'm going to close this for now then.