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

C2pa in Safari extension problem #152

Open
Kaven01 opened this issue Mar 29, 2024 · 2 comments
Open

C2pa in Safari extension problem #152

Kaven01 opened this issue Mar 29, 2024 · 2 comments

Comments

@Kaven01
Copy link

Kaven01 commented Mar 29, 2024

Hello, I am trying to create Safari extension on Mac using c2pa-js library. I have created a minimal test extension, which I paste here. It works as it is in Chrome on Windows - as a content script, when loading any page it just shows a manifest of test image in console.

But then I create a multiplatform Safari extension in XCode, replace its original Resource contents with this extension and run. Just minimal setup. Run it, enable in safari, and reload any page. I am getting the following error in console:

[Debug] c2pa:workers Fetched worker from safari-web-extension://E3BAC506-B5D9-474E-B99B-6452024AE624/scripts/thirdparty/c2pa/c2pa.worker.min.js (18594 bytes) +0ms (c2pa.esm.min.js, line 9)
[Debug] c2pa:wasm Fetching WASM binary from url safari-web-extension://E3BAC506-B5D9-474E-B99B-6452024AE624/scripts/thirdparty/c2pa/toolkit_bg.wasm +0ms – {expectedIntegrity: "sha512-vdvTW4Xzi3QAhgk4nGIc/FFSrRAuQgI1G6eKq8hcgOEqL2LfvRUrX85nPKlyEPzM8fFwtRtzRs78QqBl4iFMCw=="} (c2pa.esm.min.js, line 9)
[Debug] c2pa:wasm Sending WASM binary buffer to worker for compilation +33ms – {size: 3672108} (c2pa.esm.min.js, line 9)
[Error] TypeError: null is not an object (evaluating 'e.data.type')
(anonymous function) (c2pa.esm.min.js:18:163475)

C2pa object is not created - during "WASM compilation" in createC2pa() something receives null data in message and script crashes. It never gets to the point where it would extract manifest from image.

Am I doing something wrong, or is there any other problem?

Mac OS Sonoma 14.4.1

SafariTest.zip

@Kaven01
Copy link
Author

Kaven01 commented Apr 8, 2024

After some testing ... it seems that in Safari extension, Worker cannot pass compiled wasm Module as a part of data in outgoing postMessage(). If you try to do it, no error is displayed, but resulting message has null data. Which is problem when using worker for compileWasm operation.

A simple workaround (with unfortunate neccessity to change sourcode) is to find function fetchWasm() in c2pa.esm.js, and change the line
const wasm = await pool.compileWasm(buffer);
to
const wasm = WebAssembly.compile(buffer);

Which makes the compiles directly, not through Worker. Not exactly ideal solution, but it works.

@dkozma
Copy link
Collaborator

dkozma commented May 15, 2024

@Kaven01 good to know - we are working on a V2 API for this package and will keep this in mind.

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