DjDeveloperr / skia_canvas

Fast HTML Canvas API implementation for Deno using Google Skia
https://jsr.io/@gfx/canvas
Apache License 2.0
135 stars 9 forks source link

TypeError: this._ctx.fillText is not a function #67

Closed alexgleason closed 1 month ago

alexgleason commented 1 month ago

I finally got past https://github.com/DjDeveloperr/skia_canvas/issues/66 by upgrading to Ubuntu 24.04

Now I'm facing another issue when trying to use npm:captcha-canvas@4.0.0:

error: Uncaught (in promise) TypeError: this._ctx.fillText is not a function
    at Captcha.addDecoy (file:///root/.cache/deno/npm/registry.npmjs.org/captcha-canvas/4.0.0/js-script/captcha.js:67:23)
    at createCaptcha (file:///root/.cache/deno/npm/registry.npmjs.org/captcha-canvas/4.0.0/js-script/extra.js:19:13)
    at file:///root/captcha.ts:7:18
    at eventLoopTick (ext:core/01_core.js:175:7)

Here is my reproduction script:

import { createCaptcha } from 'npm:captcha-canvas@4.0.0';
import { createCanvas } from 'jsr:@gfx/canvas@0.5.6';

const canvas = createCanvas(300, 100);
const ctx = { ...canvas.getContext('2d'), canvas } as unknown as CanvasRenderingContext2D;

const { text } = createCaptcha({ ctx });

const uri = canvas.toDataURL();

console.log(text);
console.log(uri);
alexgleason commented 1 month ago

This method should exist: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillText

And it looks like it does exist: https://jsr.io/@gfx/canvas/0.5.6/src/context2d.ts#L307

So I'm not sure what is wrong.

alexgleason commented 1 month ago

I think it's because I'm spreading the ctx because I was trying to work around https://github.com/DjDeveloperr/deno-canvas/issues/40 in the wasm library before

Changing this:

- const ctx = { ...canvas.getContext('2d'), canvas } as unknown as CanvasRenderingContext2D;
+ const ctx = canvas.getContext('2d') as unknown as CanvasRenderingContext2D;

Seems like the right thing to do, after I looked at the source and noticed all the getter and setters. But then I get this:

root@ubuntu-s-1vcpu-512mb-10gb-nyc1-01:~# deno run -A --unstable-ffi captcha.ts
free(): invalid pointer
Aborted (core dumped)

:smiley:

EDIT: opened #68