[wp-trac] [WordPress Trac] #54568: WordPress admin overwrite JS history.state

WordPress Trac noreply at wordpress.org
Fri Dec 3 12:44:22 UTC 2021

#54568: WordPress admin overwrite JS history.state
 Reporter:  maximeschoeni  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  General        |    Version:  trunk
 Severity:  normal         |   Keywords:  has-patch
  Focuses:  javascript     |
 WordPress admin is injecting a piece of javascript at runtime
 that prevent accessing history.state. This is annoying because you cannot
 use {{{history.pushState()}}} and {{{history.replaceState()}}} functions
 properly in javascript.

 Reproduce the bug:
 1. Navigate to any wp admin page and open the browser developer console
 2. Enter {{{window.history.replaceState({name: "hello"}, null)}}} in
 3. Navigate to any other page
 4. Go back and enter {{{history.state // result -> null}}}

 The code overwrites any history.state with {{{null}}} value:
 window.history.replaceState( null, null, document.getElementById( 'wp-
 admin-canonical' ).href + window.location.hash );

 Replace {{{null}}} value by {{{window.history.state}}} (which also default
 to null):
 window.history.replaceState( window.history.state, null,
 document.getElementById( 'wp-admin-canonical' ).href +
 window.location.hash );

 The fix is very easy and has no side effect.

Ticket URL: <https://core.trac.wordpress.org/ticket/54568>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list