- From: snianu <notifications@github.com>
- Date: Wed, 12 Apr 2023 17:15:03 -0700
- To: w3c/editing <editing@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/editing/issues/424/1506128779@github.com>
Few options that we want to highlight to handle the tab/browser close scenario when there is a delay rendered format written by the web author: 1. Add a `beforeunload` event listener: A web author could choose to `preventDefault` `beforeunload` event and notify the user that there is some data pending to be written into the clipboard. In this event handler, web authors could use a new clipboard API (like `navigator.clipboard.undelayFormats([""]`) or something similar) to write the data for the formats that were delay rendered. e.g. ``` function generateExpensiveCustomFormatBlob() { // Produce the expensive data here... .... return new Blob.... } const clipboard_item = new ClipboardItem({ 'text/html': Promise.resolve(generateExpensiveCustomFormatBlob) }); navigator.clipboard.write([clipboard_item]); const beforeUnloadListener = (event) => { event.preventDefault(); navigator.clipboard.undelayFormats(['text/html']`); return (event.returnValue = ""); }; ``` **Problems with this approach** Chrome doesn't allow to customize the message that is shown to the user, so this could be confusing to the user if the default dialog shows up due to formats being delay rendered. Moreover, it's also detrimental to the performance of the site if there is a beforeunload event listener attached as it would disable bfcache. Some sites provide options to paste as plain text or html during the paste operation, so if the web author chooses to delay render both formats, but only provide the data for one format in the new web API during `beforeunload` event, then it would be a bad experience for the user if they want to choose the delay rendered format for paste. 2. Browser could choose to trigger all the callbacks before it fires `beforeunload` event so it could populate the data for the delay rendered formats. That way the web authors don't have to register for `beforeunload` event which would have disabled bfcache. In this case, a timeout can also be added to prevent sites from abusing the delay rendering of formats. **Problems with this approach** Could slow down the browser/tab close operation. The timeout is a way to mitigate this performance issue, but it could lead to other problems like the web author may not have enough time to generate the payload for the format, so the clipboard would have empty data for that format. 3. Choose to only keep the formats that are cheaper to produce and remove the rest (the formats that are delay rendered) by performing another clipboard.write operation: Native Excel has some logic to clear the clipboard and write a smaller subset of the initial formats that were on the clipboard when a user decides to close the app. Web authors can do this as well, but it would affect the experience of the user if they are unable to paste the format that has high fidelity content and is delay rendered by the web author. Also, this has to be done during `beforeunload` event which affects performance of the site by disabling bfcache and slows down browser/tab close operation. 4. Throw away all the delay rendered formats and put empty data for those formats in the clipboard: It would be a bad user experience, but a web author could also choose to not populate the formats that were registered for delay rendering. -- Reply to this email directly or view it on GitHub: https://github.com/w3c/editing/issues/424#issuecomment-1506128779 You are receiving this because you are subscribed to this thread. Message ID: <w3c/editing/issues/424/1506128779@github.com>
Received on Thursday, 13 April 2023 00:15:09 UTC