go: cmd/trace: requires HTML imports, which doesn't work on any major browser anymore
go version devel +d3595f7171 Wed Sep 18 07:29:33 2019 +0000 linux/amd64
This affects “View trace” on the web UI when running go tool trace. It doesn’t matter what the contents of the trace are; they can be from any test, for example via go test -trace=trace.out.
On Chromium 77.0.3865.75 it works, although with some warnings:
[Deprecation] HTML Imports is deprecated and will be removed in M80, around February 2020. Please use ES modules instead. See https://www.chromestatus.com/features/5144752345317376 and https://developers.google.com/web/updates/2019/07/web-components-time-to-upgrade for more details.
trace_viewer_html:3455 [Deprecation] document.registerElement is deprecated and will be removed in M80, around February 2020. Please use window.customElements.define instead. See https://www.chromestatus.com/features/4642138092470272 and https://developers.google.com/web/updates/2019/07/web-components-time-to-upgrade for more details.
(anonymous) @ trace_viewer_html:3455
(anonymous) @ trace_viewer_html:3455
trace_viewer_html:3635 [Deprecation] Element.createShadowRoot is deprecated and will be removed in M80, around February 2020. Please use Element.attachShadow instead. See https://www.chromestatus.com/features/4507242028072960 and https://developers.google.com/web/updates/2019/07/web-components-time-to-upgrade for more details.
_createLocalRoot @ trace_viewer_html:3635
_setupRoot @ trace_viewer_html:3607
_ready @ trace_viewer_html:3487
_tryReady @ trace_viewer_html:3487
_initFeatures @ trace_viewer_html:3930
__initialize @ trace_viewer_html:3438
createdCallback @ trace_viewer_html:3435
(anonymous) @ trace:94
On Firefox 69.0, it simply doesn’t work at all. http://localhost:$PORT/trace appears as a blank page. The log shows why:
ReferenceError: tr is not defined trace:59:5
onResult http://[::]:8080/trace:59
onreadystatechange http://[::]:8080/trace:43
The underying cause is that FireFox, as well as many other browsers, don’t support HTML imports. I’m not sure if they were ever widespread, but they’re clearly deprecated and non-portable at the moment. See https://caniuse.com/#feat=imports and https://developer.mozilla.org/en-US/docs/Web/Web_Components/HTML_Imports.
I realise that the docs say:
Note that while the various profiles available when launching ‘go tool trace’ work on every browser, the trace viewer itself (the ‘view trace’ page) comes from the Chrome/Chromium project and is only actively tested on that browser.
However, I don’t find that to be a good long-term plan. The tool shouldn’t depend on deprecated non-portable features, and it should work on all major browsers.
I’ve been recommending that Go developers make use of go tool trace alongside go tool pprof, but it feels much less useful if it needs a “only works on Chrome” footnote 😃
/cc @hyangah
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 19
- Comments: 25 (16 by maintainers)
Links to this issue
Commits related to this issue
- [release-branch.go1.13] cmd/trace: update to use WebComponents V0 polyfill Old trace viewer stopped working with Chrome M80+ because the old trace viewer heavily depended on WebComponents V0 which ar... — committed to golang/go by hyangah 4 years ago
- [release-branch.go1.14] cmd/trace: update to use WebComponents V0 polyfill Old trace viewer stopped working with Chrome M80+ because the old trace viewer heavily depended on WebComponents V0 which ar... — committed to golang/go by hyangah 4 years ago
With Chrome 80 now being stable, this means
go tool tracecannot display traces anymore, and the issue just got a lot more urgent 😃In case someone is on a rush, to apply the fix without delving in Gerrit, you can download the commit that fixes the issue of Go Trace from the official repository https://go.googlesource.com/go/+/47881b88c4f68bac7a002ea26753b7f042ee720a (download the .tgz) and you just need to replace the following files in your Go dir from the downloaded tgz: (Go dir is not %GOPATH%)
Running
go install cmd/tracemakes the updated tool available to use normally in go trace. The fix that Hana (Hyang-Ah) Kim uploaded makes use of 3 tokens available for ports 8001:8003 with a polyfill for the deprecated WebComponents V0, without the need to run Chrome with special flags.Hi, guys, I created a repository following
the steps given by @stapelberg:Update: use official patches now, https://go-review.googlesource.com/q/Ib575f756f5e6b22ad904ede6e4d224a995ebe259
https://github.com/kumakichi/patch-go-tool-trace
just go get and run (maybe sudo is needed)
See also https://crbug.com/1021137
Workaround:
src/cmd/trace/trace.go’stemplTracelike so:<meta http-equiv="origin-trial" content="YOUR_TOKEN_GOES_HERE">(cd src && ./make.bash)-http=127.0.0.1:8003, e.g.:Thanks. that works for me. Another alternative is to start a chrome
--enable-blink-features=ShadowDOMV0,CustomElementsV0,HTMLImportsflag.I was told that the traceviewer dev is working on a fix which may be available within one or two weeks. Not sure if we can make it before 1.14 release though.
We also need a long term transition plan. Chrome/android are moving away from trace viewer and transitioning to perfetto.dev.
Change https://golang.org/cl/219997 mentions this issue:
cmd/trace: update to use WebComponents V0 polyfill