Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to catch data from the post request #547

Open
cpamaster opened this issue Sep 16, 2023 · 4 comments
Open

How to catch data from the post request #547

cpamaster opened this issue Sep 16, 2023 · 4 comments

Comments

@cpamaster
Copy link

Hello. One page make a post request and receive json data. How to get this data by chrome-php?

@enricodias
Copy link
Member

You didn't specify how the data is received but you can intercept any request using the event method:Network.requestIntercepted. See #73 (comment) for an example.

@cpamaster
Copy link
Author

cpamaster commented Sep 16, 2023

Data is coming by xhr request.
I found one solution to catch all ajax results:

(function() {
    var open = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
        if (async) {
            this.onreadystatechange = function() {
                if (this.readyState == 4) {
                   // this.responseText - ajax result
                }
            }
        }
        return open.apply(this, arguments);
    }
})();

Copy link

stale bot commented Mar 13, 2024

This issue has been automatically marked as stale because there has been no recent activity. It will be closed after 30 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 13, 2024
@divinity76
Copy link
Contributor

divinity76 commented Nov 15, 2024

@cpamaster that would only catch XHR's.
Simplifying the example @enricodias linked to and created by @ethaniel , try

$page->getSession()->on('method:Network.requestIntercepted', function (array $params) use($page): void {
    // here you will get all info about the request :)
    var_dump($params);
    //
    $page->getSession()->sendMessage(
        new \HeadlessChromium\Communication\Message('Network.continueInterceptedRequest', [
            'interceptionId' => $params["interceptionId"]
        ])
    );
});
// Intercept all requests
$page->getSession()->sendMessage(
    new \HeadlessChromium\Communication\Message('Network.setRequestInterception', [
        'patterns' => [['urlPattern' => '*']]
    ])
);

@stale stale bot removed the stale label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants