Got malformed xml via GM.xmlHttpRequest?

I'm trying to check in the background if a linked website has the text "Gewerblicher Nutzer" (Commercial user) at a certain position. The xpath is correct, I ran several different tests.

But apparently the problem is further up, I only get a parsererror back.

What can I do, where is the mistake? Hopefully not some async/promise problem again :dizzy:

// ==UserScript==
// @name Gewerbliche kennzeichnen
// @namespace    graphen
// @version      1.0.0
// @description  Kennzeichnet oder versteckt Suchergebnisse von gewerblichen Verkäufern
// @author       Graphen
// @match*
// @noframes
// @grant        GM.xmlHttpRequest
// ==/UserScript==

/* jshint esversion: 6 */
(function (doc) {
    'use strict';

    function requestHTML(adURL) {
            method: "GET",
            url: adURL,
            onload: function(response) {
                var responseXML = null;
                // Inject responseXML into existing Object (only appropriate for XML content).
                if (!response.responseXML) {
                    responseXML = new DOMParser()
                        .parseFromString(response.responseText, "text/xml");
                console.log("XML response:");
    function isCommercial(xml) {
        let xpath = "normalize-space(//div[@id='viewad-contact']/div/ul/li[1]/span/span[@class='text-light']/text()[1])";
        var result = xml.evaluate(xpath, xml, null, XPathResult.ANY_TYPE, null);
        console.log("xPath evaluate result:");
        if (result.stringValue === "Gewerblicher Nutzer") {
            return true;
        else {
            return false;



  • Try to actually use your fallback code for xml parser:

            onload: function(r) {
                var responseXML = r.responseXML ||
                  new DOMParser().parseFromString(r.responseText, "text/xml");
                console.log("XML response:");
  • Thanks for your answer. I tried it and it's the same result :(
    But I noticed that the XML response URL isn't even the one specified in requestHTML("https://blabla.bla") but the one from the site you are currently at:
    I hope that's just a consequence of the parsererror because I have no idea why that should happen.

  • It means you can't use XML parser on an HTML document.
    Use DOMParser with text/html:

        onload: function(r) {
            var doc = new DOMParser().parseFromString(r.responseText, "text/html");
  • oh niceee it works :)
    Thanks a lot!

Logg inn eller Registrer deg for å kommentere.