By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > Javascript – How to debug “not a valid selector” without access to the offending browser page
JavaScript

Javascript – How to debug “not a valid selector” without access to the offending browser page

Admin
Last updated: 2024/02/10 at 8:22 AM
Admin
Share
2 Min Read
How to debug "not a valid selector" without access to the offending browser page

Problem:

I made a TamperScript at work (in Chrome) that gathers a list of elements from a webpage. The script is used by many people without errors. But on one person’s workstation it fails with the error:

Contents
Problem:Solution:
Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '(list of selectors)' is not a valid selector.

(list of selectors) above is a long list of selectors; but the same list works fine, not just on my machine, but on every one else’s (on the exact same webpage).

The offending workstation is remote and I don’t have access to it; how can I debug this? starting with reproducing the error?

… and where could the error come from? Is it possible that another extension causes it?

Edit: selector list:

h1, h2, h3, p-inputswitch, p-multiselect, p-multiselect-items-wrapper, input, button, a[routerlink], a.alert-item, a.btn-primary, th, label:has(+select),  div.switch-list-header, .filters-tags

Solution:

It turns out that the user had a very old version of Chrome, that for some reason didn’t update normally. It was the only case out of 60+ so nobody thought about verifying this.

Also, we found that the error wasn’t generated by Chrome directly but by an Angular polyfill (which instantiated itself for only that user, because they were using that old Chrome version).

Edit, I did code this to help with troubleshooting, if it can help someone (as per @CBroe comment)

<html>
<head><title>selector tester</title></head>
<body>
    <textarea id="sels" style="width:40em; height:10em;">h1, h2, h3, p-inputswitch, p-multiselect!=1</textarea>
    <br/>
    <button id="tester" style="margin-top: 0.8em;">testit</button>
    <script>
        const $ = document.querySelector.bind(document);
        const selectors = $("#sels").innerHTML.split(",").map(s => s.trim());
        $("#tester").addEventListener("click", e => {
            selectors.forEach(sel => console.log(sel, $(sel)));
            });
    </script>
    </body>
</html>

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Javascript - Convert hex to IEEE-754 32-bit single precision Javascript – Javascript – Convert hex to IEEE-754 32-bit single precision
Next Article Pass a function in another function and make a score counter Javascript – Pass a function in another function and make a score counter
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

How to set the dropdown value by clicking on a table row

Javascript – How to set the dropdown value by clicking on a table row

February 11, 2024
Attempting to increase the counter, when the object's tag exist

Javascript – Attempting to increase the counter, when the object’s tag exist

February 11, 2024
Cycle2 JS center active slide

Javascript – Cycle2 JS center active slide

February 10, 2024
Can import all THREE.js post processing modules as ES6 modules except OutputPass

Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass

February 10, 2024
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?