Make WordPress Core

Opened 21 months ago

Last modified 4 days ago

#62924 new defect (bug)

TinyMCE uses deprecated “unload” event listener

Reported by: hackneyprotection Owned by:
Priority: normal Milestone: 7.2
Component: TinyMCE Version: 4.0.6
Severity: normal Keywords: has-patch
Cc: Focuses: javascript

Description

Hi,

I’m encountering a deprecated feature warning in the browser console when using TinyMCE in WordPress 6.7.1.

The affected file is located at:
“/wp-includes/js/tinymce/tinymce.min.js”

Screenshot of the error: ​https://postimg.cc/rznCCPxz
Could you please check if this can be updated in the next release?
Thanks!

Attachments (1)

wordtinymceissue.png​ (14.7 KB ) - added by hackneyprotection 21 months ago.

Download all attachments as: .zip

Change History (10)

#1 @sabernhardt
21 months ago

  • Focuses ui css php-compatibility removed
  • Keywords reporter-feedback changes-requested removed
  • Version 6.7.1 → 4.0

'unload' is in the ​setDocument function, part of the TinyMCE 4.1.2 update in [29203].

The comment (in the original changeset [29203]) mentions an ​IE permissions bug, so the parent event might not be necessary anymore.

Last edited 21 months ago by sabernhardt (previous) (diff)

#2 @desrosj
21 months ago

  • Keywords reporter-feedback added; dev-feedback removed

Could you proved a bit more detail to reproduce @hackneyprotection?

For example, when you say you are using TinyMCE, are you using the Classic Editor or a custom implementation?

#3 @thomasprice61
8 weeks ago

  • Type enhancement → defect (bug)
  • Version 4.0 → 4.0.6

Chrome (and Edge) have recently blocked unload

tinymce.min.js?ver=49110-20250317:2
[Violation] Permissions policy violation: unload is not allowed in this document.

#4 @mrDollar4444
2 weeks ago

@desrosj Hi!
I can reproduce this consistently. With current Chrome it is no longer just a deprecation warning: Chrome now blocks the listener and logs a violation.

Environment

  • WordPress: 7.1.2 ($tinymce_version = '49110-20250317')
  • Chrome: 156.0.8078.47
  • Theme: default, plugins: none

Steps to reproduce

  1. Open DevTools > Console.
  2. Posts > Add New (block editor).
  3. Add a "Classic" block. ​https://i.imgur.com/w7i9OEs.png
  4. Click "Edit content". ​https://i.imgur.com/c1ngYa0.png

Result

tinymce.min.js?ver=49110-20250317:2 [Violation] Permissions policy violation: unload is not allowed in this document.

Repeated for every TinyMCE iframe. Older Chrome versions showed the message from the original report instead ("Unload event listeners are deprecated and will be removed"). It is the same code, at an earlier stage of Chrome's rollout.

#5 @sabernhardt
2 weeks ago

#66364 was marked as a duplicate.

#6 @sabernhardt
2 weeks ago

  • Keywords needs-patch added; reporter-feedback removed
  • Milestone Awaiting Review → 7.2

The console error occurs in Chrome with either the Classic Editor plugin or the Classic block.

66364-tinymce-pagehide.patch:ticket:66364​ replaces unload with pagehide in tinymce.js (only), and I question whether that if (parent.addEventListener) condition is even necessary anymore.

Whatever the solution is, the patch should:

  • update the code in both the tinymce.js and tinymce.min.js files in src/js/_enqueues/vendor/tinymce/
  • update the $tinymce_version in src/wp-includes/version.php to reflect the modified date (I recommend using the day the patch is created, which a committer could update to the day of the commit)
  • update the version information at the top of tinymce.js and tinymce.min.js to something like
    // 4.9.11 (revised 2026-10-22 to remove 'unload' event)
    

This ticket was mentioned in ​PR #14775 on ​WordPress/wordpress-develop by ​@sukhendu2002.


2 weeks ago
#7

  • Keywords has-patch added; needs-patch removed

TinyMCE registers an unload listener when its selector engine switches to an iframe document. Chromium browsers deprecate or block this listener, producing console warnings when using the Classic block or Classic Editor.

Replace unload with pagehide in both tinymce.js and tinymce.min.js, preserving the callback that resets the selector engine’s document reference.

Update both revision headers and bump $tinymce_version to invalidate cached scripts.

Use of AI Tools

AI assistance: Yes
Tool(s): Codex
Model(s): GPT 6.1 sol
Used for: Focused browser verification, code review, and PR description drafting; final implementation and tests were reviewed and edited by me.

#8 @sukhendu2002
2 weeks ago

I’ve opened a PR(​https://github.com/WordPress/wordpress-develop/pull/14775) that replaces TinyMCE’s deprecated unload listener with pagehide in both JavaScript files, updates the revision headers, and bumps $tinymce_version.

Any feedback or testing would be appreciated.

#9 @dlocc
4 days ago

Test Report

Description

This report validates that the indicated patch works as expected.

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/14775

Environment

  • WordPress: 7.2-beta3-64914-src (trunk at ​ac6f5849fa) with the patch applied
  • PHP: 8.3.35
  • Server: nginx/1.31.6 (wordpress-develop Docker environment)
  • Database: MySQL 9.7.2
  • Browser: Chrome 156.0.8078.74, headless with a clean profile
  • OS: macOS
  • Theme: Ipsum 1.0
  • Plugins: Classic Editor 1.7.0 for the Classic Editor cases, otherwise none

Steps to Reproduce

  1. Start Chrome with --enable-features=DeprecateUnload. A clean profile didn't block unload for me, and with this flag it logs the same "Permissions policy violation: unload is not allowed in this document." message from the ticket.
  2. With Classic Editor active, add a new post, type, make the text bold, switch to Text and back, save the draft, reload and publish.
  3. Without Classic Editor, add a Classic block, click "Edit contents", type, make the text bold and click "Save". Reopen and cancel twice, reopen and edit again, then save the post and reload.
  4. Count the unload violations in the console for steps 2 and 3.
  5. On a front end page with two wp_editor() instances, run a selector query in the first editor and remove its iframe. Check whether the listener ran and which document TinyMCE's selector engine (Sizzle) is left pointing at, then query the second editor.
  6. Open an editor page, go to another page and click Back. Check whether the page comes back from the back/forward cache (bfcache), then edit and save.
  7. Run everything on trunk and with the patch, with and without the flag. Repeat steps 2, 3 and 6 with tinymce.min.js, using a script_loader_src filter because /src always loads tinymce.js.

Expected Results

  • No unload violations in the console.
  • The Classic Editor and Classic block still load, edit and save.
  • Sizzle goes back to the main document when an editor iframe is removed.
  • Clicking Back doesn't break the editor.

Actual Results

Chrome blocking unload (the case in this ticket):

Case trunk PR
Classic Editor, violations with tinymce.js 19 ✅ 0
Classic Editor, violations with tinymce.min.js 18 ✅ 0
Classic block with 4 modal opens, violations with tinymce.js 14 ✅ 0
Classic block with 4 modal opens, violations with tinymce.min.js 14 ✅ 0
Listener runs when the iframe is removed No ✅ Yes
Sizzle document after the iframe is removed The removed iframe's document ✅ Main document
Classic Editor edit, save, reload, publish Works ✅ Works
Classic block edit, cancel, reopen, save, reload Works ✅ Works
Back to the front end page and the post edit screen Restored from bfcache ✅ Restored from bfcache

Chrome allowing unload (no flag):

Case trunk PR
Violations 0 ✅ 0
Listener runs when the iframe is removed Yes ✅ Yes
Sizzle document after the iframe is removed Main document ✅ Main document
Classic Editor and Classic block flows Work ✅ Work
Back to the front end page and the post edit screen Reloads (UnloadHandlerExistsInSubFrame) Restored from bfcache

Other checks:

  • tinymce.min.js differs from trunk only in the header comment and the event name, checked byte by byte since nobody can review that diff by eye.
  • Script URLs and TinyMCE's cache_suffix both move from 49110-20250317 to 49110-20261023.
  • Every restored page kept its content, and selector queries, bold, inserting content and tinymce.triggerSave() all worked.
  • No JavaScript errors in any run.

Additional Notes

  • The bfcache row is the one behavior change. With unload allowed, trunk's listener keeps editor pages out of the bfcache, and with the patch they can be restored. Chrome already restores them on trunk when unload is blocked, so this isn't new behavior for those users. On a restored post edit screen, Heartbeat ticked, the post lock came back on the first tick (with a second user on the site, since single user sites don't refresh locks) and "Save Draft" saved. Clicking Back after a save doesn't restore from the bfcache (Chrome reports no-store reasons) and shows the saved content, same as trunk.
  • @sabernhardt on your question about whether the parent event is still needed, trunk with unload blocked is effectively running without it. The listener never ran and everything above still worked. jQuery 3.7.1 in Core also limits the same workaround to IE and Edge Legacy. So I think removing it would work too, but I only tested the pagehide patch, which is the smaller change and keeps the reset.
  • On the if (parent.addEventListener) condition, the patch keeps it. The else branch is attachEvent, which is IE only, so I think that check could go either way this lands.
  • Sizzle adds another listener each time it switches back to an iframe's document, which is why trunk logs more violations than there are iframes. The handler ran 4 times for one iframe. The patch doesn't change that and it looks harmless.
  • I only tested in Chrome, so Firefox and Safari are still worth a look.

AI assistance: Yes. Claude Code (Claude Opus 5.5) for scripting and running the browser tests with Playwright and drafting this report. I reviewed the results before posting.

Note: See TracTickets for help on using tickets.