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

WASM/nodejs throws "Io Error: operation not supported on this platform" if HTML has link to google fonts api #264

Open
glove99 opened this issue Nov 1, 2023 · 5 comments

Comments

@glove99
Copy link

glove99 commented Nov 1, 2023

My HTML has links to google font apis:

<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans:100,200,300,400,500,600,700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Mono:100,200,300,400,500,600,700&display=swap" rel="stylesheet">

Running inline() will throw an UnhandledPromiseRejection and kill the nodejs app. The error message is "Io Error: operation not supported on this platform". I replicated on MacOS and a RHEL container.

If I set load_remote_stylesheets: false then the problem stops.

Not sure if there is something specific about the google font api or a larger problem with loading remote stylesheets.

@Stranger6667
Copy link
Owner

Hi @glove99

Thank you for reporting and sorry for the confusing error message!

The issue is that our core crate sends requests via attohttpc which does not support WASM. Can you share some code snippets so I can work with them and maybe use them in the test suite?

Probably, the solution will be to switch to reqwest (#246) or make it extendable, so in wasm bindings, we use e.g. web_sys to make network calls

@glove99
Copy link
Author

glove99 commented Nov 1, 2023

Ah that makes sense. Here is a simple test case that fails:

  it('replicate remote link error', async () => {
    const html =
      '<html><head>\
      <link href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans:100,200,300,400,500,600,700&display=swap" rel="stylesheet">\
      <link href="https://fonts.googleapis.com/css?family=IBM+Plex+Mono:100,200,300,400,500,600,700&display=swap" rel="stylesheet">\
    </head><body>Test</body></html>';

    const output = inline(html, {});
    console.log(output);
  });

@glove99
Copy link
Author

glove99 commented Nov 2, 2023

BTW, while debugging this problem I dived into your project code. Really impressive. I always love learning I don't know near as much as I thought I did. 😄

@Stranger6667
Copy link
Owner

@glove99 Sorry for the delay!

Thank you for the reproduction code! Happy to hear that you found the source code useful :) Let me know if you have any questions about it, I'd be happy to chat :)

On the issue side - I will fix the ongoing build failure and then look into switching the library that makes requests in the core crate first (maybe in a couple of weeks) and then will update the WASM bindings.

@Stranger6667
Copy link
Owner

FWIW, I updated the error text, so it clearly communicates the current state of things. Network requests are not supported on WASM now (though they work in the new, not yet released napi bindings) + the readme is updated to reflect it too.

Though, it should be possible, here is an example with fetch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants