Coder Social home page Coder Social logo

a doubt about botasaurus HOT 3 CLOSED

omkarcloud avatar omkarcloud commented on July 28, 2024
a doubt

from botasaurus.

Comments (3)

Chetan11-dev avatar Chetan11-dev commented on July 28, 2024 1

Not Currently, it's in backlog, I except to do it this year. Till then you can use code like execute_js and run similar code

(function () {

    if (window.hasRun) {
        return
    }
    window.hasRun = true

    // Store the original fetch function in a variable
    const originalFetch = window.fetch


    window.fetch = async function (...args) {
        
        if (true) {
            try {
                // Call the original fetch function
                const response = await originalFetch.apply(this, args)

                // Clone the response to not interfere with the original processing
                const clonedResponse = response.clone()

                // Read the response as JSON and log it
                clonedResponse.json().then(json => {
                        console.log(json)
                })

                // Return the original response
                return response
            } catch (error) {
                console.error('Error in fetch interceptor:', error)
                throw error // Re-throw the error for proper error handling
            }
        }
        else {
            // Call the original fetch function for other URLs
            return originalFetch.apply(this, args)
        }
    }


    
})()```

from botasaurus.

Chetan11-dev avatar Chetan11-dev commented on July 28, 2024

use this code to spy on xhr

    var originalSend = XMLHttpRequest.prototype.send

    // Override the send method
    XMLHttpRequest.prototype.send = function () {
        // Keep a reference to the XMLHttpRequest instance
        var xhr = this

        // Function to handle the state change
        function onReadyStateChange() {
            if (xhr.readyState === 4) { // Check if the request is complete
                try {
                        // Attempt to parse JSON response
                        var json = JSON.parse(xhr.responseText)
                        // Log the URL and JSON response to the console
                        console.log("URL: " + xhr.responseURL)
                        console.log("Response: ", json)
                        window.data = json


                } catch (e) {
                    // If response is not JSON, log an error
                    console.error("Could not parse JSON response for URL: " + xhr.responseURL)
                }
            }
        }

        // Add the event listener for 'readystatechange'
        this.addEventListener('readystatechange', onReadyStateChange)

        // Call the original send method
        originalSend.apply(this, arguments)
    }

from botasaurus.

ConnorMAD avatar ConnorMAD commented on July 28, 2024

ty

from botasaurus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.