Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda