Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

[HELP] JsFunction and download process #14

Closed
wislem opened this issue Jul 12, 2018 · 4 comments
Closed

[HELP] JsFunction and download process #14

wislem opened this issue Jul 12, 2018 · 4 comments

Comments

@wislem
Copy link

wislem commented Jul 12, 2018

Hello,

Great job on the package, works like a charm!

My issue has to do more than usage rather than a bug report.

I have managed to go through the log in and navigation process in my DFP account and am now trying to download a CSV file from in there.

The download is triggered through a button that sends a POST request and the actual path of the file is returned in the response of that request. Then a new tab opens and the download dialog opens.

I would love to download the file in the disk, meaning, continue using puppeteer on the newly opened tab and download it. For now I just tried to get the response. Any advice on the download process would be greatly appreciated!

    $page = $this->login(true);

    // Navigation, working just fine!
    $page->click('.sidebar-options .section:nth-child(7) a.section-title');
    $page->click('a[href="#admin/policy-center"]');
    $page->click('a[href="#admin/policy-download"]');
    $page->click('dropdown-button._ngcontent-ADMIN-3._nghost-ADMIN-4');
    $page->click('dropdown-button._ngcontent-ADMIN-3._nghost-ADMIN-4');
    $page->click('.options-wrapper > div[group] > material-select-dropdown-item:nth-child(2)');
    $page->click('div.download');
    // Here is where the POST request occurs

    $page->waitFor(2*1000);

    // How wrong is this? :)
    $response = $page->on('response', ['pageResponse' => JsFunction::create('pageResponse', "
        if ('xhr' !== response.request().resourceType()){
            return ;
        }
        response.text().then(function (textBody) {
            return textBody;
        })
    ")]);

    dd($response);

I am getting the error below:

Nesk\Rialto\Exceptions\Node\FatalException: The "listener" argument must be of type Function in file D:\workspace\laragon\www\ocmbots\vendor\nesk\rialto\src\ProcessSupervisor.php on line 230

Screenshot of the post request and response when the download button is clicked:

image

Environment (please complete the following information):

  • OS: Windows 10
  • Node version: 9.2.0
  • PHP version 7.2.2

My Node package manager is:
NPM 6.1.0

@nesk
Copy link
Member

nesk commented Jul 13, 2018

Your a bit out of luck here… 😕

First, it seems like Puppeteer itself doesn't really support file downloads for the moment.

Second, it's not currently possible for PuPHPeteer to retrieve a value from an event, this is partially due to the lack of concurrency in PHP. This could be solved by implementing some kind of “value retriever” in Rialto, but I have to think properly about this before writing anything. If I find a good solution, I will notify you. 🙂

I'm closing the issue since this mainly concerns Rialto instead of PuPHPeteer, but feel free to answer.

@nesk nesk closed this as completed Jul 13, 2018
@yangweijie
Copy link

when i simulate to login some website to get cookie, there comes alert dialog. how to write like js code below same with php?

	page.on('dialog', async dialog => {
	    console.log(dialog.message());
	    await dialog.dismiss();
	    // await browser.close();
	});

@RosiersRobin
Copy link

Your a bit out of luck here… 😕

First, it seems like Puppeteer itself doesn't really support file downloads for the moment.

Second, it's not currently possible for PuPHPeteer to retrieve a value from an event, this is partially due to the lack of concurrency in PHP. This could be solved by implementing some kind of “value retriever” in Rialto, but I have to think properly about this before writing anything. If I find a good solution, I will notify you. 🙂

I'm closing the issue since this mainly concerns Rialto instead of PuPHPeteer, but feel free to answer.

Is there any update on this?

@nesk
Copy link
Member

nesk commented Apr 3, 2019

I've created an issue about this a few days ago, to present a potential solution and track the progress. But I didn't start to write any code and I will probably not start working on this until v2 is out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants