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

document is not supporting inside JS function which called by isolate_worker #7

Closed
deepbhavsar opened this issue Sep 29, 2021 · 2 comments

Comments

@deepbhavsar
Copy link

I am creating the element using the document.createElement('input') inside the JS function. I am calling that function using the JsIsolatedWorker().run(functionName: 'alertMessage',arguments: '100') It is giving me error:

This is my JS function. I am getting image using input type=file. Plan is to return file path from this function.

async function createDynamicInput() {
var input = document.createElement('input');
input.type = 'file';
input.onchange = e => {
   var file = e.taralertMessageget.files[0];
   console.log(file);
   return file;
}
input.click();
}

Calling this function using:

var result = await JsIsolatedWorker().run(
        functionName: 'createDynamicInput',
        arguments: '100',
      );
      print("==$result");

Error: ReferenceError: document is not defined.

Let me know the correct way or require to make changes into current code. Thanks

@iandis
Copy link
Owner

iandis commented Sep 29, 2021

Hi, have you imported the script file using JsIsolatedWorker.importScripts first before running the function?

Edit:
The main problem actually comes from calling the document since it's not available on Web Workers. reference

@iandis iandis closed this as completed Oct 4, 2021
@iandis
Copy link
Owner

iandis commented Oct 4, 2021

Closing this as this is not the package's issue itself.

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