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

Clipboard is broken on Mac Catalyst WebView #1322

Open
cyanzhong opened this issue Oct 22, 2022 · 10 comments
Open

Clipboard is broken on Mac Catalyst WebView #1322

cyanzhong opened this issue Oct 22, 2022 · 10 comments

Comments

@cyanzhong
Copy link

cyanzhong commented Oct 22, 2022

Mac Catalyst is a technique introduced by Apple to bring iOS apps to Mac, it uses UIKit instead of AppKit even when running on macOS.

That being said, a WKWebView on macCatalyst inherits from UIView, which behaves differently in some ways compared to the native WKWebView on Mac apps.

I tested ProseMirror on Monterey running on Mac Catalyst, and it seems copying content from the editor doesn't work (cannot paste into other places).

The root cause seems that we need to enable brokenClipboardAPI even when browser.ios && browser.webkit_version < 604 gives us false: https://github.com/ProseMirror/prosemirror-view/blob/master/src/input.ts#L550

I can help get more info regarding system versions and SDK versions if you want to fix this (e.g., whether this is fixed in Ventura), totally understand the priority since using Mac Catalyst is already a niche choice.

Exactly the same phenomenon happens in CodeMirror too.

@marijnh
Copy link
Member

marijnh commented Oct 22, 2022

Do I understand correctly that this webview inherits all the Mobile Safari bugs, and we should somehow try to detect it and enable our iOS workarounds?

@cyanzhong
Copy link
Author

cyanzhong commented Oct 22, 2022

Thanks for the quick response!

this webview inherits all the Mobile Safari bugs

This is my assumption but I'm not entirely sure, could you please point out some iOS bugs so that I can verify on Mac Catalyst?

somehow try to detect it

For now I actually cannot tell from navigator.userAgent and navigator.platform, they look the same as native Mac apps (if this cannot be done properly, a new option might be the way to go).

I ended up by setting a fake user agent, telling ProseMirror the browser is both iOS and older than 604.

@igandrews
Copy link

@cyanzhong How are you seeing this problem manifest? I ask because we use prosemirror within a WKWebView in iOS & Catalyst and haven't found any issues with the clipboard. I can copy content and it's correctly within the Mac pasteboard and so can be pasted into other places in the app or other applications.

@cyanzhong
Copy link
Author

@igandrews I just wrote a minimal repro:

import UIKit
import WebKit

class ViewController: UIViewController {
  private let webView = WKWebView(frame: .zero)

  override func viewDidLoad() {
    super.viewDidLoad()

    webView.load(URLRequest(url: URL(string: "https://prosemirror.net/")!))
    view.addSubview(webView)
  }

  override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    webView.frame = view.bounds
  }
}

image

The copied content can only be pasted into the ProseMirror editor, not anywhere else.

What's your OS version? I am using macOS 12.6, building the sample using Xcode 14.1. Also, do you have a custom user agent in your app?

@igandrews
Copy link

igandrews commented Oct 26, 2022

@cyanzhong I do not have a custom user agent. I am also in Mac 12.6 but my Xcode version is 13.4.1. And when I copy to the clipboard (e.g. select all and copy the default prosemirror.net content) I see the pasteboard with that content and can paste elsewhere:
image

What do you have in the pasteboard? The fact that you can paste within prosemirror would indicate something is in the clipboard (unless prosemirror uses some local/internal fallback storage I'm not aware of). Wonder if it relates to the custom clipboard format changes being discussed/made.

@cyanzhong
Copy link
Author

cyanzhong commented Oct 27, 2022

@igandrews This is a great way to investigate, thanks for sharing. It turns out when I use the default UA, I have something in the clipboard:

It seems there's no plain-text variant, that's probably why I cannot paste it into text boxes that only accepts plain text.

When I fake the UA (to enable the brokenClipboardAPI check), I have this:

@cyanzhong
Copy link
Author

cyanzhong commented Oct 27, 2022

@igandrews Alright, I think I figured out. I downloaded Xcode 13.4.1 and tried again, it works just fine as you mentioned.

The issue seems like a regression in the new SDK (Xcode 14), that is why you haven't seen this issue. Hope this helps.

image

I will Ventura later today, not sure if it's still there.

@marijnh
Copy link
Member

marijnh commented Oct 27, 2022

So do I understand correctly that this isn't really something ProseMirror can work around?

@igandrews
Copy link

@marijnh Yeah I think this is just a webkit/wkwebview issue imo.

@cyanzhong I'm actually seeing the html only format in my app too and have another dev using ventura and they see that so guessing you will find the issue is still there. Seems like something bad in webkit though I didn't spend the time to track it down. Maybe you want to report it to them. For me I worked around this for now by hooking the cut and copy (after the editor view creation to ensure I'm hooking after it does) and then I later on update the pasteboard. Not ideal but it works for now.

@masegraye
Copy link

FYI - the recently released .NET MAUI Blazor Hybrid stuff from Microsoft uses Mac Catalyst for compiling to macOS, so you may see more of this issue. (I just came across this myself, trying exactly this.)

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

4 participants