Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
How to evaluate an xmlhttpRequest

I'm trying to make a tampermonkey script using firefox in which i use an xmlhttpRequest to retrieve external information, but I keep getting the same error in the console: "Uncaught DOMException: Node cannot be used in a document other than the one in which it was created". I don't want to use the responseText to look for the information I need, I want to turn it into a DOM on which I can apply evaluate and refer to elements. But the way I'm doing it doesn't seem to work. Anybody knows how I can handle this?

GM_xmlhttpRequest({
        method: "get",
        url: someurl,
        onload: function(responseDetails) {
            if(responseDetails.readyState == 4 && responseDetails.status == 200){
                    var parser = new DOMParser()
                    var to_DOM = parser.parseFromString(responseDetails.responseText, "text/html")
                    alert(to_DOM.evaluate("//tr[@bgcolor]/b[1]",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0).innerText)
            }
        }
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are referencing the document that is loaded in the browser, not the document of what you created.

const parser = new DOMParser()
const responseText = "<html><body><p><strong>Hello World</strong><p></body></html>";
const doc = parser.parseFromString(responseText, "text/html");
console.log(document.evaluate("//p/strong", doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).innerText)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda