HighCWu/waifu2x-tfjs

OffscreenCanvas is not defined

gqgs opened this issue · 4 comments

gqgs commented
  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

const canvas = new OffscreenCanvas(320, 200);

This call breaks in browsers without OffscreenCanvas support.
https://caniuse.com/offscreencanvas

It seems the script still works fine without the call to tf_webgl.setWebGLContext.

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

const canvas = new OffscreenCanvas(320, 200);

This call breaks in browsers without OffscreenCanvas support.
https://caniuse.com/offscreencanvas

It seems the script still works fine without the call to tf_webgl.setWebGLContext.

OffscreenCanvas can be used for Web worker background processing to avoid UI freezes. This is a new feature of newer browsers. I recommend upgrading the browser. Maybe I will try to add a compatibility check in a future version .

gqgs commented

@HighCWu Thanks for the reply. A possible hotfix would be just checking if the browser has support in that section.

if (typeof OffscreenCanvas !== "undefined") {
    const canvas = new OffscreenCanvas(320, 200);
    let context = canvas.getContext('webgl2');
    if (!context) {
        context = canvas.getContext('webgl');
        if (context)
            tf_webgl.setWebGLContext(1, context);
    }
    else {
        tf_webgl.setWebGLContext(2, context);
    }
}

The UI will freeze if it is undetected but for now it might be better than the script not working at all.
Unfortunately upgrading the browser it's not a option for a lot of people as you can see in the caniuse link above.
Firefox, Safari and IE still don't support OffscreenCanvas in their latest versions.

@HighCWu Thanks for the reply. A possible hotfix would be just checking if the browser has support in that section.

if (typeof OffscreenCanvas !== "undefined") {
    const canvas = new OffscreenCanvas(320, 200);
    let context = canvas.getContext('webgl2');
    if (!context) {
        context = canvas.getContext('webgl');
        if (context)
            tf_webgl.setWebGLContext(1, context);
    }
    else {
        tf_webgl.setWebGLContext(2, context);
    }
}

The UI will freeze if it is undetected but for now it might be better than the script not working at all.
Unfortunately upgrading the browser it's not a option for a lot of people as you can see in the caniuse link above.
Firefox, Safari and IE still don't support OffscreenCanvas in their latest versions.

Thanks. I'll try it later.