mathlive icon indicating copy to clipboard operation
mathlive copied to clipboard

Errors in the console when pasting in a sandboxed iframe and paste does not work

Open RambabuPatina opened this issue 3 months ago • 9 comments

Description

The 'Paste to Clipboard' option does not paste and showing errors in the console when pasting in a sandboxed iframe

Steps to Reproduce

  1. Include the editor in a iframe and include virtual keyboard
  2. Copy some text and click on virtual keyboard
  3. Click on 'Paste from clipboard' Screenshot 2024-04-08 at 5 09 26 PM

Actual Behavior

The paste behaviour does not work and shows errors in the console:

[Violation] Permissions policy violation: The Clipboard API has been blocked because of a permissions policy applied to the current document. See https://goo.gl/EuHzyv for more details. Uncaught (in promise) DOMException: Failed to execute 'readText' on 'Clipboard': The Clipboard API has been blocked because of a permissions policy applied to the current document. See https://goo.gl/EuHzyv for more details. at Object.pasteFromClipboard [as fn]

Expected Behavior

Paste from clipboard should work and No error messages

Environment

MathLive version 0.97.1

macOS/Windows, Chrome/Firefox

RambabuPatina avatar Apr 08 '24 11:04 RambabuPatina

Does this happen with the current version (0.98.6)?

arnog avatar Apr 08 '24 12:04 arnog

Checked with 0.98.6 version, same issue facing. Do we need additional changes to work in the iframe? Thanks in Advance

RambabuPatina avatar Apr 08 '24 13:04 RambabuPatina

Hi @arnog , Any clue on the issue?

RambabuPatina avatar Apr 10 '24 09:04 RambabuPatina

Not yet, and I will need to build a project to try to reproduce the problem before I can debug it.

arnog avatar Apr 10 '24 13:04 arnog

Any update @arnog ? One of our releases is based on this. Thanks

rkanumola avatar Apr 15 '24 05:04 rkanumola

It would help if you had a project to share that reproduces the problem.

arnog avatar Apr 15 '24 06:04 arnog

@rkanumola are you loading the iframe from the same location as the container doc?

gunnarmein-ts avatar Apr 17 '24 22:04 gunnarmein-ts

@gunnarmein-ts Do you mean location means the domain? The iframe being loaded from other location. I.e the parent document and the iframe domains are different.

RambabuPatina avatar Apr 18 '24 10:04 RambabuPatina

This article: https://stackoverflow.com/questions/61401384/can-text-within-an-iframe-be-copied-to-clipboard mentions: "To use the API in iframes, you need to enable it with Permissions Policy, which defines a mechanism that allows for selectively enabling and disabling various browser features and APIs. Concretely, you need to pass either or both of clipboard-read or clipboard-write, depending on the needs of your app."

<iframe src="index.html" allow="clipboard-read; clipboard-write"></iframe>

Can you try that?

gunnarmein-ts avatar Apr 18 '24 14:04 gunnarmein-ts