-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
x/build: add js/wasm Chrome/Firefox capable trybot #26051
Comments
@neelance, would a browser-based builder be helpful for anything? I imagine yes, at least for DOM interaction. |
Hmm... I don't expect the core packages to do much DOM interaction. That should all go into libraries. |
In any case, since 99% of users will use Go's wasm support to target browsers, testing in browsers instead of Node still seems like it makes sense, even if v8 is the same in at least Chrome's case. |
This looked interesting, so I took a stab at this. I looked into headless Chrome and used the puppeteer library to interact with the browser through an API. It took some fighting to figure out the kinks but now I have been able to run the tests completely using puppeteer. So all wasm tests are running completely inside the browser ! I am yet to run all the tests. But I have 2 concerns
Thoughts ? I can put up a DNS CL for people to play around, but just wanted to get the conversation going here. |
Interesting @agnivade; for running GopherJS tests in browser with https://github.com/myitcv/gjbt (very alpha) I went with https://godoc.org/github.com/sclevine/agouti, on the basis it can drive any browser (although for now
Assuming we need an npm package, which might not be the case, there will still be a requirement to have Chrome/Firefox etc available on such a builder. So is this such an issue? On the plus side, if we can get a good, robust setup in place it will, like Clearly this doesn't require that we ship something with the core Go distribution, but this brings us back to @bradfitz's comment in #26051 (comment)
Would be interesting to have a look through, thanks. |
Ah nice, a Go solution is certainly preferred by me. Since we would like to have a common interface to drive any browser, how about https://github.com/tebeka/selenium ? Have you had any experience with it ? I was wondering if it is better than agouti or are they both kinda the same.
It just adds the headache of maintaining an extra package.json. Otherwise, it is fine by me. In any case, I am going to investigate the Go based approaches first. |
Unfortunately not. |
Presumably a browser-based trybot would let us test the net/http Fetch code and catch regressions like: https://go-review.googlesource.com/c/go/+/123537 |
I will look into a pure Go solution this weekend and update here. From the looks of it, we need to serve the index.html, wasm.exec.js and the target wasm file by spinning up a web server and point the Chrome/Gecko Driver to it. And just capture the console logs. |
If |
Yes, but then the the Using puppeteer, I had to stub out Open to any other suggestions that you have. |
You're more than likely miles ahead of me here so I'll defer to you 😄 |
I have managed to get a beta version here - https://github.com/agnivade/wasmbrowsertest. Unfortunately, there is no FF support because the log API is not supported by geckodriver. I was very surprised this wasn't properly documented anywhere. Overall, the process wasn't as trivial as I thought it would be. Since the driving process is now in Go, the interop between Go and JS is now much harder, than Node and JS. 2 things were particularly tricky -
) These are simply replaced directly in the node-based Anyways, tests are running now. The only blocking issue is that some tests are trying to open files. (like But those pass in nodeJS because obviously Please feel free to clone the repo and try it out. I apologize for the messy code. I initially thought of using |
Would also help to diagnose/repro #26748 |
Looked into this a bit more. There is a non-standard filesystem API which is implemented only by Chrome. https://developer.mozilla.org/en-US/docs/Web/API/Window/requestFileSystem. Using this, we can read/write files from the browser. So, if we implement the But unfortunately, the sync versions of those APIs, which is what we need to use to call from Go space, do not work. The page itself says So unless we can use the async APIs, it does not seem possible to read/write files from browser. The So as it stands -
|
ping @neelance - Any thoughts on this ? |
Change https://golang.org/cl/137236 mentions this issue: |
@agnivade The above CL makes it use the async APIs. Hope this helps. |
Awesome, Thank you ! I will check with this and update. |
This commit makes syscall on js/wasm use the asynchronous variants of functions in Node.js' fs module. This enables concurrency and allows the API of the fs module to be implemented with an alternative backend that only supports asynchronous operations. Updates #26051. Change-Id: Ibe1dcc988469fc11c3b8d8d49de439c12ddaafce Reviewed-on: https://go-review.googlesource.com/c/137236 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The FS APIs turned out to be much more unstable than I thought. Even a simple file read is throwing a If I try to write to a new file using This is the read file code that I am trying. I have tried with keeping index.html in the webserver root as well as window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
function errorCb(e) {
var msg = '';
console.error('Error: ' + e);
}
function successCb(fs) {
fs.root.getFile('index.html', {}, function(fileEntry) {
console.log(fileEntry)
}, errorCb);
}
navigator.webkitPersistentStorage.requestQuota(10*1024*1024, function(grantedBytes) {
window.requestFileSystem(window.PERSISTENT, grantedBytes, successCb, errorCb);
}, function(e) {
console.log('Error', e);
}); My Chrome version is 69 along with ( Further notes: even if this works, I don't see any API to retrieve/write to a fd from a file, which is required for file operations to work. |
Native filesystem APIs are coming back. https://blog.chromium.org/2019/09/chrome-78-beta-new-houdini-api-native.html. All hope is not lost. |
Any progress on this issue? |
Actually, we don't need the filesystem APIs at all for this. It should be possible to achieve this by extending wasmbrowsertest and a little bit of extra customization to wasm_exec, to behave like a pass-through layer which forwards all file-system calls to the webserver, which then makes the actual calls and relay it back to the browser. That should make for more robust code and avoid some puppeteer edge-cases which I have been following up with the Chrome team without much success. I don't have enough free time these days to work on wasm stuff. But it is not that complicated if someone wants to send a PR. Otherwise I'll get to it whenever I have some time. |
Follow on from #26015 (comment)
With a Chrome and/or Firefox capable trybot we'd be able to do more interesting WASM tests in a headless browser-based JS VM, and so have access to the DOM etc.
This issue is to decide whether or not such a trybot would be useful and therefore worth the effort.
The text was updated successfully, but these errors were encountered: