Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!