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

Writing to properties fails in browser #785

Closed
fatadel opened this issue Jun 12, 2022 · 6 comments · Fixed by #809
Closed

Writing to properties fails in browser #785

fatadel opened this issue Jun 12, 2022 · 6 comments · Fixed by #809
Assignees
Labels
binding-http Issues related to http protocol binding browser-bundle Issues related to the browser distribution of node-wot bug Something isn't working core Issues with the core library

Comments

@fatadel
Copy link
Contributor

fatadel commented Jun 12, 2022

Create foo.html with the following code:

<script src="https://cdn.jsdelivr.net/npm/@node-wot/browser-bundle@latest/dist/wot-bundle.min.js"></script>
<script>
    const servient = new Wot.Core.Servient();
    servient.addClientFactory(new Wot.Http.HttpClientFactory());
    const helpers = new Wot.Core.Helpers(servient);
    servient.start().then((thingFactory) => {
        helpers
            .fetch('http://plugfest.thingweb.io:8083/testthing')
            .then((td) => {
                thingFactory.consume(td).then((thing) => {
                    thing.writeProperty('bool', false);
                });
            })
            .catch((error) => {
                window.alert("Could not fetch TD.\n" + error);
            });
    });
</script>

Expected result:
No errors, successful write operation.

Actual result:
Error in console, write operation not performed.

image

@relu91 relu91 added bug Something isn't working binding-http Issues related to http protocol binding browser-bundle Issues related to the browser distribution of node-wot core Issues with the core library labels Jun 13, 2022
@derwehr
Copy link
Contributor

derwehr commented Jun 21, 2022

I get a similiar error trying to write to properties:

from-browser.js:2 Uncaught (in promise) Error: Readable.from is not available in the browser
    at module.exports (from-browser.js:2:9)
    at Readable.from (_stream_readable.js:1115:12)
    at ContentSerdes.valueToContent (content-serdes.js:112:61)
    at ConsumedThing.eval (consumed-thing.js:428:54)
    at Generator.next (<anonymous>)
    at eval (consumed-thing.js:28:71)
    at new Promise (<anonymous>)
    at __awaiter (consumed-thing.js:24:12)
    at ConsumedThing.writeProperty (consumed-thing.js:415:16)

A work-around, that involves editing /dist/ files I found is:
Changing /node_modules/@node-wot/core/dist/content-serdes.js line 92 from

if (value instanceof es2018_1.ReadableStream) {

to

if (value instanceof ReadableStream) {

With this editing /dist/ files, this is of course not viable, but might help in finding the problem.

@relu91 relu91 self-assigned this Jun 24, 2022
@sebastiankb
Copy link
Contributor

just for record: the webui app has the same problem when I call an action:

image

@relu91
Copy link
Member

relu91 commented Jun 29, 2022

After plumbing into the inner workings of broserify and the Web platform, I've found that sadly stream upload is not supported for browsers. This means that we can't use a stream to write properties or invoke actions. Solving this issue is going to be tricky but I hope to find a patch that will only be active on browser environments.

For the ones that are curious. Here are the relevant issues:
whatwg/fetch#1438
https://bugs.chromium.org/p/chromium/issues/detail?id=688906

@relu91
Copy link
Member

relu91 commented Jun 29, 2022

PR in flight; it should fix the issue but it is a workaround due to my previous comment. I would close this issue when it is properly merged and keep track of #785 (comment) in another issue.

@danielpeintner
Copy link
Member

@relu91 I am not sure if the issue is really solved.
I tried the WebUI and I still run into issues

Error: Readable.from is not available in the browser

Note: It is different to the one @sebastiankb and others were seeing before...

To reproduce the problem

  1. Build node-wot
  2. Open <node-wot-folder>/examples/browser/index.html locally in a browser and consume http://plugfest.thingweb.io:8083/testthing
  3. Invoke "int-int" action

@danielpeintner danielpeintner reopened this Jul 4, 2022
relu91 added a commit to relu91/thingweb.node-wot that referenced this issue Jul 27, 2022
The builtins were wrongly passed in the root configuration object. They
should be set in the `builtins` property.

Close eclipse-thingweb#785
Signed-off-by: reluc <relu.cri@gmail.com>
@danielpeintner
Copy link
Member

FYI: I updated the online version also.
see http://plugfest.thingweb.io/webui/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding-http Issues related to http protocol binding browser-bundle Issues related to the browser distribution of node-wot bug Something isn't working core Issues with the core library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants