Skip to content

electron and web workers #6932

Description

@cvlmtg

Hi, we are developing an app which runs in the browser and as an electron app. There's been a release that has introduced this code:

if (typeof module !== 'undefined' && module.require) {
   // node.js - disable worker and set require.ensure.
   PDFJS.disableWorker = true;
   ...

The problem is that module.require exists in electron too, so web workers are disabled even if they should not. I patched pdf.js this way:

if (typeof window === 'undefined' && typeof module !== 'undefined' && module.require) {
   // node.js - disable worker and set require.ensure.
   PDFJS.disableWorker = true;
   ...

and it seems to work. I think this patch should not cause other unwanted troubles, so could it be possibile to add it to pdf.js?

Activity

  1. yurydelendik commented on Jan 28, 2016

    @yurydelendik
    Contributor

    We cannot introduce typeof window === 'undefined' -- the stubs for window object can be added to global. Can we rely on something else, e.g. process?

  2. cvlmtg commented on Jan 28, 2016

    @cvlmtg
    Author

    I think it should be ok, I'll check it tomorrow. I was thinking about __filename too, but it doesn't exists in node repl, just when evaluated in a script.

  3. cvlmtg commented on Jan 29, 2016

    @cvlmtg
    Author

    ok I think this might do:

    node

     ~ node
    > process.versions.electron
    undefined
    

    electron

    process.versions.electron
    "0.36.5"
    

    I'll do some tests with this code:

    if (typeof module !== 'undefined' && module.require && typeof process.versions.electron === 'undefined') {
  4. Rob--W commented on Jan 31, 2016

    @Rob--W
    Member

    What about ditching duck-typing of the environment and using typeof Worker !== 'function' instead?

  5. cvlmtg commented on Feb 2, 2016

    @cvlmtg
    Author

    I think that should be ok too

  6. yurydelendik commented on Apr 7, 2016

    @yurydelendik
    Contributor

    Fixed our dependence on stub for worker, so typeof worker === 'undefined' check shall work now. See #7126 and it shall fix this issue.

  7. cvlmtg commented on Apr 8, 2016

    @cvlmtg
    Author

    thanks, we'll try it soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions