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

Widgets are inserted into the user's content when body.isContentEditable #8094

Closed
fregante opened this issue Mar 29, 2024 · 9 comments
Closed
Assignees
Labels
bug Something isn't working customer Required for a customer projct specification required

Comments

@fregante
Copy link
Contributor

fregante commented Mar 29, 2024

Describe the bug

Our widgets will be injected into this page and, if the content editable field/frame is read by a controller (as one would expect), it will include our widgets

<!doctype html>
<body contenteditable>
   Hello user, type something here
</body>

To Reproduce

  1. Visit https://contenteditable-body.tiiny.site

Actual behavior

  • See our widgets end up inside the contenteditable field, in the DOM, and are potentially saved as part of the user input
  • Our widgets (including the notifications) are selectable/editable

Expected behavior

I'm not sure of how to deal with this. At at very least we can add a contenteditable=false attribute to all of our widgets (part of #7670)

Demo

Screenshot 23
Screen.Recording.3.mov

Context

Seen in https://github.com/pixiebrix/pixiebrix-source/issues/322

@fregante fregante added the bug Something isn't working label Mar 29, 2024
@fregante
Copy link
Contributor Author

fregante commented Mar 29, 2024

Thoughts

  • We cannot hide the elements from the reader, they can use .innerHTML at any time to "save" all of the elements
  • Our shadow DOM already hides the actual content, providing that we stop using mode=open on the shadow DOM

Provisional resolutions

Also

@grahamlangford
Copy link
Collaborator

grahamlangford commented Mar 29, 2024

The toast is not in a shadow dom. We don't have this problem with the Snippet Shortcut Menu, and it's in a mode=open shadow dom. I would be against requiring mode=closed. I'm not convinced it does anything for us, and closed shadow doms are harder to write tests for.

@fregante
Copy link
Contributor Author

The toast is not in a shadow dom

Indeed it looks like the shadow dom already does not inherit contenteditable, so this specific issue does not apply. However the content is still accessible and editable by the host website's JavaScript

I'm not convinced it does anything for us

It does what it says on the tin, and it says isolation is good for safety and reliability. Content scripts are specifically run in an isolated context to avoid conflicts and increase security, this continues on that line.

closed shadow doms are harder to write tests for

I mentioned this before, all we need is something like mode={process.env.SHADOW_MODE}, also easily enforceable via lint; we already have a custom ENV specific to E2E so it's a solved problem.

Anyway for this issue the mode isn't relevant so I crossed those off.

@twschiller
Copy link
Contributor

twschiller commented Apr 8, 2024

I'm not sure of how to deal with this. At at very least we can add a contenteditable=false attribute to all of our widgets

Given that this case arises with certain editors, IMO the correct long-term fix is to render the elements on the on the parent frame (which IIRC is what Grammarly does).

To solve/prevent the immediate problem of data corruption in editors, I would recommend the following immediate approach for body[contenteditable] (just body[contenteditable] for now, but we might consider :

Show in top-level frame:

Throw an error (mod developer should just have these run in the top-level frame):

  • Modal
  • Popover (display temporary information with "popover" location)

Ensure PixieBrix always cleans up the container:

  • Snippet shortcut menu
  • Text selection menu

Editors Impacted (in playground, we should include runtime tests):

  • TinyMCE 6
  • CKEditor 4
  • CKEditor 5

For Salesforce CKEditor 4, I'm seeing some weird behavior where the toast is showing in the editor before I think the context menu action is even run: https://github.com/pixiebrix/pixiebrix-source/issues/322. Update: that alert had gotten saved in the editor

@twschiller twschiller added customer Required for a customer projct and removed triage labels Apr 8, 2024
@BLoe
Copy link
Contributor

BLoe commented May 13, 2024

The alert popups are no longer rendered inside the <body/> element in the page, so they seem to no longer suffer from this issue? I can't produce the behavior from the initial video anymore. Is this issue still a real problem that users suffer from?

image

@twschiller
Copy link
Contributor

Moving to "Next" - I'm also having trouble reproducing on the Salesforce edit field right now: https://pixiebrix3-dev-ed.lightning.force.com/lightning/r/Case/5008X00002YDcUtQAL/view. But I'm not aware of what would have changed

@twschiller twschiller self-assigned this May 13, 2024
@BLoe
Copy link
Contributor

BLoe commented May 13, 2024

The "widget" used to be appended to body here:

document.body.append(container, style);

Federico fixed the issue in this PR

Now, the widget is added directly to document instead, see here

@BLoe
Copy link
Contributor

BLoe commented May 13, 2024

@twschiller I think we should close this issue unless you see a reason otherwise, given the above change

@twschiller
Copy link
Contributor

twschiller commented May 13, 2024

Thanks for clarifying - will close and we can reopen as necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working customer Required for a customer projct specification required
Development

No branches or pull requests

4 participants