This seems to be indeed necessary in order to detect invalid selectors like `[foo="bar"`. But just change the code like that:

    doc.head.appendChild(styleElement);
    try
    {
      styleElement.sheet.insertRule(selector + " {}");
      return true;
    }
    catch (e)
    {
      return false;
    }

And it will also handle all the cases currently covered by `document.querySelector()`.