Title: document.querySelector null Error
Last modified: June 30, 2024

---

# document.querySelector null Error

 *  Resolved [susanwrotethis](https://wordpress.org/support/users/susanwrotethis/)
 * (@susanwrotethis)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/)
 * Hi, we’re running WP 6.5.5 and Smush 3.16.5. While debugging something unrelated,
   I noticed a Smush-related console error when a role that cannot access Smush 
   in the WP Admin menu is updating content.
 * The message is: Uncaught TypeError: document.querySelector(…) is null
 * The URLs I’ve seen this on include:
 * [https://(site-redacted)/wp-admin/post-new.php](https://(site-redacted)/wp-admin/post-new.php)
   
   [https://(site-redacted)/wp-admin/edit.php?post_type=post](https://(site-redacted)/wp-admin/edit.php?post_type=post)
   [https://(site-redacted)/wp-admin/post.php?post=1234&action=edit](https://(site-redacted)/wp-admin/post.php?post=1234&action=edit)
 * In digging around, it appears to be a reference to a JS snippet that adds an 
   event listener. It includes the line:
 * document.querySelector( ‘#toplevel_page_smush li:last-child a’ ).target=”_blank”;
 * Since this ID exists in the WP Admin menu only for higher-level users, it is 
   sometimes null. Hoping you can fix this in a future release. Thanks!
 * Edited to add:
 * I did some further testing, creating a post, saving it as a draft, and publishing
   it, and on publishing I received two additional errors that are presumably related.
   The summary:
 * [https://(site-redacted)/wp-json/wp/v2/users?context=view&who=authors&per_page=50&_fields=id,name&_locale=user](https://(site-redacted)/wp-json/wp/v2/users?context=view&who=authors&per_page=50&_fields=id,name&_locale=user)
   
   rest_forbidden_whoSorry, you are not allowed to query users by this parameter.
   403
 * [https://(site-redacted)/wp-json/wp/v2/blocks?context=edit&per_page=100&_locale=user](https://(site-redacted)/wp-json/wp/v2/blocks?context=edit&per_page=100&_locale=user)
   
   rest_forbidden_contextSorry, you are not allowed to edit posts in this post type.
   403
 * The related request info was empty. When I deactivate Smush and repeat the process
   I stepped through in creating, saving, and publishing, these errors are no longer
   generated. Again, this is a lower-level (custom) role that has Editor-level access
   to posts, but only to posts. Despite the errors, the items do save/publish.
    -  This topic was modified 1 year, 11 months ago by [susanwrotethis](https://wordpress.org/support/users/susanwrotethis/).
    -  This topic was modified 1 year, 11 months ago by [susanwrotethis](https://wordpress.org/support/users/susanwrotethis/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdocument-queryselector-null-error%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [susanwrotethis](https://wordpress.org/support/users/susanwrotethis/)
 * (@susanwrotethis)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/#post-17859494)
 * Additional info: the rest_forbidden_who and rest_forbidden_context errors do 
   not appear when all plugins other than Smush are deactivated, so I am looking
   elsewhere in regards to those. The querySelector error remains, however.
 *  [Kris – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport13/)
 * (@wpmudevsupport13)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/#post-17860097)
 * Hi [@susanwrotethis](https://wordpress.org/support/users/susanwrotethis/)
 * I hope you are doing well today.
 * Thank you for all the details.
 * Can you let us know which plugin you use to create that custom role so that we
   can be on the same page to replicate this in the first place and we could share
   that with our developers for review?
 * Kind Regards,
   Kris
 *  Thread Starter [susanwrotethis](https://wordpress.org/support/users/susanwrotethis/)
 * (@susanwrotethis)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/#post-17860678)
 * Hi Kris, I found last night that it doesn’t even have to be a custom role (we
   roll our own, BTW — no pun intended). An Author or Contributor role experience
   the same issue. This is re the original querySelector issue. As regards the additional
   info I sent, I’m investigating further, but I’m increasingly convinced this isn’t
   related to Smush and was coincidental that it came up at the same time.
 * Thanks!
 * Susan
    -  This reply was modified 1 year, 11 months ago by [susanwrotethis](https://wordpress.org/support/users/susanwrotethis/).
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/#post-17863063)
 * Hi [@susanwrotethis](https://wordpress.org/support/users/susanwrotethis/)
 * Thanks for response!
 * I checked it again closer and you were right from the start – it actually is 
   related to Smush.
 * The good news is that it will not affect any features of the plugin or cause 
   any issues with how it works. It’s not a matter of any conflict either. You can
   safely ignore it for now but I am reporting it to our developers to get it fix
   with one of future releases – it shouldn’t be happening anyway.
 * **As for what it is and why it happens: **
 * It’s related to the upselling notificaitons in the free version of plugin. We
   do show some upsell notifications to promote the Pro version of the plugin. Currently
   those notifications are only:
 * – a modal upon first install of the plugin (or after plugin reset to factory 
   settings) and it only shows in the plugin (not in other areas of back-end)
 * – and a dedicated menu “Upgrade” section in the plugin.
 * In the past we also used to also show sort of a banner at the top of the backend
   pages and the script that is cauing that error is related to it.
 * That banner is no longer there (we do not use that kind of upsell anymore) but
   apparently the script was missed and left there. In any case, all the upsell 
   messages were also showing up only to the admins, hence no no error for admin
   users.
 * As mentioned, I already reported it to our developers to be fixed in future releases(
   not sure if it will be in nearest one or one of the later ones) but you can also
   safely ignore that error for now.
 * Thank you for reporting it!
 * Best regards,
    Adam
 *  Thread Starter [susanwrotethis](https://wordpress.org/support/users/susanwrotethis/)
 * (@susanwrotethis)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/#post-17866586)
 * That’s really helpful and informative. Thanks so much. Sometimes I give demos
   to executives who know just enough to want to go down rabbit holes over irrelevant
   details. The fewer “why is that showing an error?” questions I need to field,
   the shorter our meetings are. 🙂
 * Appreciate all you folks do. Thanks again!
 * Susan
 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/#post-17885477)
 * Hi [@susanwrotethis](https://wordpress.org/support/users/susanwrotethis/)
 * I hope you’re well today!
 * It seems we have accidentally missed notification about your response. I’m sorry
   about that!
 * Anyway, I’m glad I could help and thank you for response.
 * I’m marking this as resolved then but if you have any additional/follow-up questions
   on this subject, let us know and we’ll get back to you.
 * Best regards,
    Adam
 *  [jvwx](https://wordpress.org/support/users/enfueggo/)
 * (@enfueggo)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/#post-18018587)
 * Came here to report the same issue: getting error `Uncaught TypeError: Cannot
   set properties of null (setting 'target')` on seemingly all admin pages. Would
   be nice to have this fixed to make debugging other issues easier. [@wpmudev-support8](https://wordpress.org/support/users/wpmudev-support8/)
 *  Plugin Support [Jair – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport15/)
 * (@wpmudevsupport15)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/#post-18022587)
 * Hi [@enfueggo](https://wordpress.org/support/users/enfueggo/),
 * I understand your frustration, and I apologize for not being able to provide 
   you with a specific timeframe for a fix. However, please rest assured that our
   Smush team strives to fix each bug as quickly as possible.
 * Kind regards,
   Zafer

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘document.querySelector null Error’ is closed to new replies.

 * ![](https://ps.w.org/wp-smushit/assets/icon-256x256.gif?rev=3447113)
 * [Smush – Image Optimization, Compression, Lazy Load, WebP & CDN](https://wordpress.org/plugins/wp-smushit/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-smushit/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-smushit/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-smushit/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-smushit/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-smushit/reviews/)

 * 8 replies
 * 5 participants
 * Last reply from: [Jair – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport15/)
 * Last activity: [1 year, 8 months ago](https://wordpress.org/support/topic/document-queryselector-null-error/#post-18022587)
 * Status: resolved