PDFIUM is not working in Webkit(playwright)

224 views
Skip to first unread message

Kamesh Rajendran

unread,
Feb 21, 2024, 3:44:37 AMFeb 21
to pdfium

We are encountering a problem with the pdfium module in WebKit during Playwright testing. The provided sample code is designed to inform the client side once both the document and pdfium.wasm has been successfully loaded. This code ensures that both the pdfium module and the DOM are fully loaded before proceeding.


<!DOCTYPE html>

<html lang="en">

<head>

    <script src="pdfium.js"></script>

 

    <script>

        window.createDivElement = function (value) {

            var divElement = document.createElement("div");

            divElement.textContent = value;

            divElement.style = "Left:20px;Width: 300px; Height:50px"

            document.body.appendChild(divElement);

        }

        document.addEventListener("DOMContentLoaded", function () {  

            let pageLoaded = false;

            let moduleLoaded = false;

            window.createDivElement("Start DOM Loading...");

            // Module. onRuntimeInitialized will be called from pdfium.js to notify the user for further process

            Module.onRuntimeInitialized = async _ => {

                moduleLoaded = true;

                window.createDivElement("PDFIUM Module Loaded...");

                checkIfEverythingWasLoaded();

            };

            function checkIfEverythingWasLoaded() {

                if (pageLoaded && moduleLoaded) {

                    window.createDivElement("Both Page and M    odule loaded...");

                }

            }

            window.onload = function (e) {

                window.createDivElement("Page Loaded...");

                pageLoaded = true;

                checkIfEverythingWasLoaded();

            }

        });

    </script>

</head>

<body>

    @RenderBody()

    <script src="_framework/blazor.server.js"></script>

</body>

</html>

Please find the blazor sample: WEBKIT~1739968950.zip

The table below illustrates the outcomes of executing the aforementioned code in both Chrome and WebKit. In the case of WebKit (Playwright), the Module.onRuntimeInitialized event fails to trigger, preventing us from proceeding with subsequent steps to read the document.

chrome vs webkit.png

For image reading, we utilized pdfium.wasm, loading only the pdfium.js file into the application. The pdfium.js file, in turn, loads the pdfium.wasm file independently and notifies the success handler for further processing. This mechanism functions correctly in major browsers such as Chrome, Edge, Firefox, and Safari. However, it encounters an issue in the webkit environment.


Upon closer examination, we found that within the pdfium.js file, WebAssembly.instantiateStreaming is employed to read the .wasm file. However, in Safari, this method fails to return either a success or failure handler.


Wekit-pdfium-issue.png

Can anyone redirect us if you have any idea on this?

Note : 

We used the below comment to run the application in WebKit with Node version v16.20.1  

Kamesh Rajendran

unread,
Feb 26, 2024, 11:41:12 PMFeb 26
to pdfium
Hi Everyone,

Can any one help on this?

K. Moon

unread,
Feb 27, 2024, 3:01:45 AMFeb 27
to Kamesh Rajendran, pdfium
It looks like you're using a WebAssembly build of PDFium. The PDFium project doesn't provide support for this. If you're using someone else's WebAssembly build of PDFium, you'll need to ask them for support.

It's possible someone else in this community has solved a similar issue, but given that noone has responded, I don't think anyone has.

--
You received this message because you are subscribed to the Google Groups "pdfium" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/bbc43b2a-63d1-48ce-97f1-bebc289e7585n%40googlegroups.com.

Lei Zhang

unread,
Feb 27, 2024, 1:14:50 PMFeb 27
to Kamesh Rajendran, pdfium, K. Moon
Reply all
Reply to author
Forward
0 new messages