Skip to content

[Bug]: drag & drop does not work in prebuilt viewer from certain sources #19979

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

Open
rolait opened this issue May 30, 2025 · 0 comments
Open
Labels

Comments

@rolait
Copy link

rolait commented May 30, 2025

When "dragover" is called, a dropEffect is set for the drag event, depending on the value of effectAllowed of the event. When e.g. dragging & dropping from the Desktop, then effectAllowed is usually all and everything works. However, from certain sources, the effectAllowed is uninitialized (this happened e.g. with an electron app). The effect is that the drop event is never triggered. If we look at the code in app.js, then we see that in both cases the drop effect is set to move by the pdfjs viewer code. However, setting the drop effect with an unitialized value for effectAllowed somehowblocks the triggering of the subsequent drop event.

Commenting out evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move"; solves this issue. I was able to reproduce this behavior in Firefox and Edge. Maybe this line can just be removed, because, if I am not mistaken, it has no practical value (except in some browsers/operating systems, where the browser shows a different cursor?).

Code in app.js:

// Enable dragging-and-dropping a new PDF file onto the viewerContainer.
      appConfig.mainContainer.addEventListener("dragover", function (evt) {
        for (const item of evt.dataTransfer.items) {
          if (item.type === "application/pdf") {
            evt.dataTransfer.dropEffect =
              evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
            stopEvent(evt);
            return;
          }
        }
      });

Web browser and its version

Firefox 138.0.4

Operating system and its version

Ubuntu 22.0.4 / Windows 10

PDF.js version

5.2.133

Is the bug present in the latest PDF.js version?

Yes

Is a browser extension

No

Steps to reproduce the problem

The behavior can be simulated by adding e.dataTransfer.effectAllowed = "uninitialized"; at the beginning of the above cited dragover function. If added, then dragging & dropping from the desktop does not work anymore.

  1. Add e.dataTransfer.effectAllowed = "uninitialized"; to the dragover function.
  2. Open the viewer.html of the the newest pre-built version
  3. Drag a PDF from the desktop into the viewer: it does not open anymore in the viewer (but in some cases, the browser opens the pdf as file://... instead)

What is the expected behavior?

The pdf should be loaded in the pdf js viewer

What went wrong?

drag & dropping the pdf is not possible.

Link to a viewer

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants