rialto-php / puphpeteer Goto Github PK
View Code? Open in Web Editor NEWA Puppeteer bridge for PHP, supporting the entire API.
License: MIT License
A Puppeteer bridge for PHP, supporting the entire API.
License: MIT License
Hi,
I'm trying to push a button, then a video loads and then I want to be able to "log" what the next requests are... Is this possible and how?
Current code I have:
$puppeteer = new Puppeteer(['read_timeout' => 130, 'log_browser_console' => true]);
$browser = $puppeteer->launch();
$page = $browser->newPage();
// Load the website
$page->goto('http://example.com', ['waitUntill' => 'networkidle2']);
// execute the javascript to click an element
$page->click('#PlayerZone > div.placeholder__wrapper > div.player__placeholder.lozad > i > svg');
// Get the response headers
// Close the browser
$browser->close();
I hope this is possible and someone is able to help me here!
Kindest regards
Robin
Hi,
Im getting the below-mentioned error, please check and clarify
"Right-hand side of 'instanceof' is not an object" (In Process.php line 230:)
When I turn on the debug true,
TypeError: Right-hand side of 'instanceof' is not an object
at PuppeteerConnectionDelegate.handleInstruction (/media/administrator/Storage/Projects/vp/BssApi/vendor/extractr-io/puphpeteer/src/P
uppeteerConnectionDelegate.js:44:19)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
I actually removed the lines instance of Brower checking and it is working fine.
My Environment details
Hi
I'm trying to get the complete HTML but it's returning null.
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch();
$page = $browser->newPage();
$page->goto( 'https://google.com' );
$page->waitFor(5000);
$page_meta = $page->evaluate(JsFunction::create("
return {
body: document.body.innerHTML
};
"));
var_dump( $page_meta );
It will work with this:
$page_meta = $page->evaluate(JsFunction::create("
return {
body: document.querySelector('#main').innerHTML
};
"));
This issue is a PuPHPeteer extension for the features proposed in rialto-php/rialto#8. The goal is to listen to the console
event on each page created by PuPHPeteer and write the browser logs in the PHP logger.
addScriptTag does not work, see example:
Reproducible example
$this->page->goto($url);
$res = $this->page->addScriptTag([
"path" => "my_script_in_current_working_dir.js"
]);
$result = $this->page->evaluate(JsFunction::createWithBody("function_from_script_call();"));
Expected behavior
The function should be executed
Generated logs
Fatal error: Uncaught Nesk\Rialto\Exceptions\Node\FatalException: Evaluation failed: ReferenceError: function_from_script_call is not defined
Environment (please complete the following information):
My Node package manager is:
Done.
I tried some hello world code in your readme.
and i got this error
Nesk/Rialto/Exceptions/ProcessUnexpectedlyTerminatedException with message 'The process has been unexpectedly terminated.'
im trying in tinker environment
use Nesk\Puphpeteer\Puppeteer;
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch(); // here the exception triggered
what did i do wrong?
Hello,
your example in the readme
use Nesk\Rialto\Exceptions\Node;
try {
$page->tryCatch->goto('invalid_url');
} catch (Node\Exception $exception) {
// Handle the exception...
}
is that compatible with PHP 7 or the catch part is just recognized by PHP 5?
thanks
Currently, PuPHPeteer locks the minor version used for Puppeteer because its exports aren't applying semver (see #22) and can change between releases.
Once the exports are no longer an issue, the version lock could be done on the major number instead of the minor one, this would allow users to install the latest version of Puppeteer or even an old one.
Notes:
Hi, this is help request.
How to get element and read and work with them like getAttribute etc.
I found solution for read getProperty in #5 .
Example:
$divs = $page->querySelectorAll('div'); foreach($divs as $div) { $attribute = $div->getAttribute('data-value'); .... }
Thanks
use Nesk\Puphpeteer\Puppeteer;
use Nesk\Rialto\Data\JsFunction;
require_once '../vendor/autoload.php';
$puppeteer = new Puppeteer();
$browser = $puppeteer->launch();
$page = $browser->newPage();
$response = $page->goto('http://xxgk.yichang.gov.cn/index.html');
$page->type('#vc_title', '人社局', ['delay' => 100]);
$page->click('#search_xxgk');
$page->waitFor(3000);
$dimensions = $page->evaluate(JsFunction::createWithBody("
return {
html: document.documentElement.outerHTML
};
"));
file_put_contents('/tmp/search.html', $dimensions['html']);
$browser->close();
PHP Fatal error: Uncaught Nesk\Rialto\Exceptions\Node\FatalException: Protocol error (Input.insertText): 'Input.insertText' wasn't found in /data/wwwroot/spider/vendor/nesk/rialto/src/ProcessSupervisor.php:307
Stack trace:
#0 /data/wwwroot/spider/vendor/nesk/rialto/src/ProcessSupervisor.php(387): Nesk\Rialto\ProcessSupervisor->checkProcessStatus()
#1 /data/wwwroot/spider/vendor/nesk/rialto/src/Traits/CommunicatesWithProcessSupervisor.php(83): Nesk\Rialto\ProcessSupervisor->executeInstruction(Object(Nesk\Rialto\Instruction))
#2 /data/wwwroot/spider/vendor/nesk/rialto/src/Traits/CommunicatesWithProcessSupervisor.php(91): Nesk\Rialto\Data\BasicResource->proxyAction('call', 'type', Array)
#3 /data/wwwroot/spider/demo/xxgk.php(44): Nesk\Rialto\Data\BasicResource->__call('type', Array)
#4 {main}
thrown in /data/wwwroot/spider/vendor/nesk/rialto/src/ProcessSupervisor.php on line 307
Why is that? Can you help me, thanks.
With this code, the browser logs will be retrieved and passed to the PHP logger:
$puppeteer->launch()->newPage();
However, when using the page initially created by the browser, it will not work:
$puppeteer->launch()->pages[0];
Hello,
sometimes I had this error on php log
Cannot read property 'port' of null
and today many times in a row, so the php script doesn't run at all and the complete error is
[12-Jun-2018 18:44:03 Europe/Berlin] PHP Fatal error: Uncaught Symfony\Component\Process\Exception\ProcessFailedException: The command "'node' '/home/myuser/public_html/tmp/pjs/vendor/nesk/rialto/src/node-process/serve.js' '/home/myuser/public_html/tmp/pjs/vendor/nesk/puphpeteer/src/PuppeteerConnectionDelegate.js' '{"idle_timeout":60}'" failed.
Exit Code: 1(General error)
Working directory: /home/myuser/public_html/tmp/pjs
Output:
================
Error Output:
================
/home/myuser/public_html/tmp/pjs/vendor/nesk/rialto/src/node-process/Server.js:49
process.stdout.write(`${this.server.address().port}\n`);
^
TypeError: Cannot read property 'port' of null
at Server.writePortToOutput (/home/myuser/public_html/tmp/pjs/vendor/nesk/rialto/src/node-process/Server.js:49:54)
at Object.<anonymous> (/home/myuser/public_html/tmp/pjs/vendor/nesk/rialto/src/node-process/serve.js:18:8)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/ in /home/myuser/public_html/tmp/pjs/vendor/nesk/rialto/src/ProcessSupervisor.php on line 232
Is there a fix about it? Thanks
title says it all, is there an option for it?
The methods declared in AliasesEvaluationMethods and AliasesSelectionMethods should be typed.
Hi. How can I log/display browser errors in php code?
Currently, the resource type is detected with instanceof
.
However, since Puppeteer exports aren't using semver (see puppeteer/puppeteer#3067), we should stop relying on this and instead check the resource type by reading the [resource].constructor.name
property:
if (_.get(value, 'constructor.name') === 'Browser') {
this.browsers.add(value);
}
if (this.options.log_browser_console === true && _.get(value, 'constructor.name') === 'Page') {
value.on('console', this.logConsoleMessage);
}
Describe the bug
A clear and concise description of what the bug is.
Reproducible example
// Provide a full example reproducing the bug
Expected behavior
A clear and concise description of what you expected to happen.
Generated logs
Provide the logs generated by your example, see how to get them in the guidelines for contributing to this repository:
https://github.com/nesk/puphpeteer/blob/master/.github/contributing.md#provide-logs-with-your-bug-report
The generated logs
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
My Node package manager is:
Additional context
Add any other context about the problem here.
I want see the chromium, So i write this code:
$puppeteer = new Nesk\Puphpeteer\Puppeteer;
$browser = $puppeteer->launch(['headless' => false]);
$page = $browser->newPage();
$page->goto('https://example.com');
echo $page->content();
I got the right output, but i didn't see the chromium。
My development environment is:
php 7.1.18 (wampserver)
node 10.15.3
windows 10
Does anyone have the same problem as me?
Hello,
the PHP usual code...here on CentOS 7
require 'vendor/autoload.php';
use Nesk\Puphpeteer\Puppeteer;
use Nesk\Rialto\Exceptions\Node;
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch([
'args' => ['--no-sandbox', '--disable-setuid-sandbox', '--proxy-server=xx.xx.xxx.xx:3128'],
]);
$page = $browser->newPage();
...
My setup:
OS CentOS Linux 7.5.1804
Node v9.11.2
PHP 7.1.22
NPM 6.2.0
nesk Puppeteer 1.8.0
nesk Rialto 1.2.1
Here newPage()
doesn't work anymore and the script stops:
[01-Oct-2018 12:36:05 Europe/Berlin] PHP Fatal error: Uncaught Error: Call to a member function newPage() on null in /home/myuser/public_html/foder/project/myscript.php:203
Stack trace:
#0 {main}
thrown in /home/myuser/public_html/foder/project/myscript.php on line 203
Do you know the reason, please? Thank you very much
Some resources inherit from other ones, for example, ElementHandle
inherits from JSHandle
, we should apply this to the PHP resources.
How could I do this with puphpeteer? The docs were unclear.
await page.waitFor('dev.myElementHasSpawned').then( async() => {
// Ok now let's do some stuff here
});
Hi hope you can help on that one :
Describe the bug
i have some code using puphpeteer that can run from the prompt on a ubuntu16.04 remote server, but
trying to launch the exact same program on a cron job result with an error
i can reproduce the same error with the code example given in your doc
Reproducible example
on the "crontab -e " i enter :
/usr/bin/php /home/level1/level2/Phantom/pupetteer/petitTest.php
petitTest.php :
use Nesk\Puphpeteer\Puppeteer;
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch();
$page = $browser->newPage();
$page->goto('https://example.com');
$page->screenshot(['path' => 'example.png']);
$browser->close();
**Expected behavior**
Again running that program directly from command line is fine but not on the cron job
**Generated logs**
PHP Fatal error: Uncaught Symfony\Component\Process\Exception\ProcessFailedException: The command "'node' '/home/level1/level2/Phantom/pupetteer/vendor/nesk/rialto/src/node-process/serve.js' '/home/level1/level2/Phantom/pupetteer/vendor/nesk/puphpeteer/src/PuppeteerConnectionDelegate.js' '{"idle_timeout":60}'" failed.
Exit Code: 1(General error)
Working directory: /home/level1
/home/level1/level2/Phantom/pupetteer/vendor/nesk/rialto/src/node-process/Server.js:17
constructor(connectionDelegate, options = {})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/home/level1/level2/Phantom/pupetteer/vendor/n in /home/level1/level2/Phantom/pupetteer/vendor/nesk/rialto/src/ProcessSupervisor.php on line 232
**Environment :**
- OS: Ubuntu 16.04
- Node version: v10.6.0
- PHP version: PHP 7.2.7-1+ubuntu16.04.1+deb.sury.org+1 (cli)
My Node package manager is:
- NPM (6.2.0)
**Additional context**
Add any other context about the problem here.
Jumping between Pupheteer docs, Puppeteer docs, the code, and trusty Stackoverflow but I don't seem to be making any headway.
Can you provide an example of how to use Puphpeteer to get the text content of a div by ID, and value of an input by ID? Right now I'm headed down the querySelectorEval
path, but I'm mostly getting empty arrays.
Thanks!
We should configure Travis CI to run tests with PHP 7.3.
Describe the bug
I have changed the Puppeteer syntax for loading a browser and added the headless syntax from the Puppeteer, but it creates an error when I run it.
Reproducible example
I have tried all of the following:
$browser = $puppeteer->launch({headless: false});
$browser = $puppeteer->launch(headless: false);
$browser = $puppeteer->launch(headless: 'false');
Expected behavior
I'm sure it's a syntax issue, but my Puppeteer project was working completely fine, but I need it to interact with variables in PHP so staying in PHP would be so much easier. I just need to convert my code properly. Thanks. I appreciate your work but there isn't much documentation on how to convert an existing project over to PHP, though that may be something I should know how to do, I am struggling. Thanks again.
Environment (please complete the following information):
Describe the bug
Getting Certificate Authority failures:
production.ERROR: net::ERR_CERT_AUTHORITY_INVALID at http://jaspur.nl {"exception":"[object] (Nesk\\Rialto\\Exceptions\\Node\\FatalException(code: 0): net::ERR_CERT_AUTHORITY_INVALID at http://jaspur.nl at /home/foobar.com/vendor/nesk/rialto/src/ProcessSupervisor.php:307)
Reproducible example
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch();
$page = $browser->newPage();
$page->goto($url = 'http://jaspur.nl');
$page->screenshot(['path' => 'example.png');
$browser->close();
Expected behavior
A Screenshot
Error logs
production.ERROR: net::ERR_CERT_AUTHORITY_INVALID at http://jaspur.nl {"exception":"[object] (Nesk\\Rialto\\Exceptions\\Node\\FatalException(code: 0): net::ERR_CERT_AUTHORITY_INVALID at http://jaspur.nl at /home/foobar.com/vendor/nesk/rialto/src/ProcessSupervisor.php:307)
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
My Node package manager is:
Hello,
please, can you better explain with other examples?
Eg. after $page->goto($url);
does it mean that $page contains the page content or how to get the entire page content inside a variable?
That is, I need to surf a page as if I were in front of the screen and then extract all the hrefs of this page searching in the page content
thanks
I forgot to add the Accessibility
resource, this is an easy fix.
Sorry to bother you, but I have got Puphpeteer fully working. The idea is great and love how easy it is to setup. However I've no clue how to make really proper use of it (beyond making screenshots). Maybe it' s that I am not familiar enough Puppeteer and Rialto, but I hope you can help.
For example I want to extract all (text) content from all td-nodes on a page, I would start with:
$tds = $page->querySelectorAll('td');
Now I have an array of ElementHandle objects. But what would be next? The objects itself are only references to the element in Chrome/Puppeteer context, but how would I extract information from them?
foreach($tds as $td) { $text = $td->innerText; // Do something }
Would seem most straightforward, but is obviously not working.
Then looking at the documentation and some guessing, maybe something like this seemed an idea, however that is failing as well:
foreach($tds as $td) { $text = $page->evaluate(JsFunction::create( " return td.innerText; ", ['td' => $td])); }
However $text stays null.
What would the right direction be? I am probably misreading and interpreting the documentation, but I have no idea were to go from here.
Describe the bug
When installing on ubuntu 18 with php 7.3
Fails to install
Reproducible example
composer require nesk/puphpeteer
Expected behavior
installation works :)
Generated logs
Provide the logs generated by your example, see how to get them in the guidelines for contributing to this repository:
https://github.com/nesk/puphpeteer/blob/master/.github/contributing.md#provide-logs-with-your-bug-report
Using version ^1.4 for nesk/puphpeteer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Installation failed, deleting ./composer.json.
[ErrorException]
"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
My Node package manager is:
When attempting to do something such as
$page->_client->on("Security.certificateError", function ($event) use ($page) {
$page->_client->send('Security.handleCertificateError', [
"eventId" => $event->eventId,
"action" => "continue"
]);
});
I receive the following error:
Nesk \ Rialto \ Exceptions \ Node \ FatalException
"listener" argument must be a function
Is there a way to implement listeners using this bridge, or should I stick with writing a node script and then just referencing that from within my PHP scripts?
Describe the bug
I tried to use PuPHPeteer but I had trouble with the node command, so I send the execution path of node to the constructor and now a have an "Unknown Error". It is triggered while trying to execute this command:
"C:\Program Files\nodejs\node" "C:\laragon\www\scrapers-refactoring\vendor\nesk\puphpeteer\src/get-puppeteer-version.js"
I tried this in a terminal and it works fine and returns "1.13.0".
Reproducible example
use Nesk\Puphpeteer\Puppeteer;
$logger = new \Monolog\Logger('PuPHPeteer');
$logger->pushHandler(new \Monolog\Handler\StreamHandler('puPHPeteer.log', \Monolog\Logger::DEBUG));
$puppeteer = new Puppeteer(
[
'executable_path' => 'C:\Program Files\nodejs\node',
'logger' => $logger,
'log_node_console' => true,
'log_browser_console' => true,
'debug' => true,
]
);
Expected behavior
Create a Puppeteer instance.
Generated logs
There were no logs generated, probably because the issue is in the constructor
Environment (please complete the following information):
My Node package manager is:
Additional context
I'm using Laragon, so I don't know if it's a configuration thing, any help would be nice :)
Hi, I've just started to use puphpeteer and its working very nicely. Thank you for the library.
I do have one query regarding how to get data back from the screenshot
method if I do NOT wish to save it to a file.
At the moment to get a screenshot your docs say:
use Nesk\Puphpeteer\Puppeteer;
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch();
$page = $browser->newPage();
$page->goto('https://example.com');
$page->screenshot(['path' => 'example.png']);
$browser->close();
Taking a look at the API docs over on the puppeteer site:
https://pptr.dev/#?product=Puppeteer&version=v1.6.2&show=api-pagescreenshotoptions
I would like to be able to grab a base64 (or binary) string of the image received and process it directly rather than have to save it to disk.
Would there be anyway to do that at the moment, say something like this:
use Nesk\Puphpeteer\Puppeteer;
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch();
$page = $browser->newPage();
$page->goto('https://example.com');
$imageString = $page->screenshot(['encoding' => 'base64']);
//Do things with $imageString without having to worry about a file saved on disk
$browser->close();
At the moment I can't find a way to get any data out of the BasicResource
object that gets returned from ->screenshot
Thank you!
Can you add the option to set the executable path of chrome?
Hello,
it works fine with the example.com but if eg. you try the domain icecat.de as target,
the page content returns NULL
I'm on CentOS 7 + PHP 7.1 and Nodejs 9
These are the script lines:
require 'vendor/autoload.php';
use ExtractrIo\Puphpeteer\Puppeteer;
$puppeteer = new Puppeteer;
$browser = $puppeteer->launch([
'args' => ['--no-sandbox', '--disable-setuid-sandbox'],
]);
$page = $browser->newPage();
$response = $page->goto('https://icecat.de');
var_dump($page->content());
$browser->close();
there are other not working tested URLs but I don't write them here and I kindly ask you to find the cause and fix it to work with any site, please
Thank you
Hi. How can I emulate devices?
Getting the following when attempting to run the first simple example in the documentation of taking a screenshot of example.com
Notice: Use of undefined constant SOCKET_EAGAIN - assumed 'SOCKET_EAGAIN' in C:\xampp\htdocs\assets\APIs_vendor\puppeteer\vendor\nesk\rialto\src\ProcessSupervisor.php on line 430
Fatal error: Uncaught Socket\Raw\Exception: Socket operation failed: A non-blocking socket operation could not be completed immediately. (SOCKET_EWOULDBLOCK) in C:\xampp\htdocs\assets\APIs_vendor\puppeteer\vendor\clue\socket-raw\src\Exception.php:55 Stack trace: #0 C:\xampp\htdocs\assets\APIs_vendor\puppeteer\vendor\clue\socket-raw\src\Exception.php(24): Socket\Raw\Exception::createFromCode(10035, 'Socket operatio...') #1 C:\xampp\htdocs\assets\APIs_vendor\puppeteer\vendor\clue\socket-raw\src\Socket.php(247): Socket\Raw\Exception::createFromSocketResource(Resource id #52) #2 C:\xampp\htdocs\assets\APIs_vendor\puppeteer\vendor\nesk\rialto\src\ProcessSupervisor.php(409): Socket\Raw\Socket->read(1024) #3 C:\xampp\htdocs\assets\APIs_vendor\puppeteer\vendor\nesk\rialto\src\ProcessSupervisor.php(382): Nesk\Rialto\ProcessSupervisor->readNextProcessValue(true) #4 C:\xampp\htdocs\assets\APIs_vendor\puppeteer\vendor\nesk\rialto\src\Traits\CommunicatesWithProcessSupervisor.php(83): Nesk\Rialto\ProcessSupervisor->executeInstruction in C:\xampp\htdocs\assets\APIs_vendor\puppeteer\vendor\clue\socket-raw\src\Exception.php on line 55
Running on Windows 10 with PHP 7.1
Installed with composer as mentioned in the instructions.
Need a little help here, can't figure our where to i can tweak this option, if there is one:
The timeout (30.000 seconds) has been exceeded while reading the socket of the process. Maybe you should increase the "read_timeout" option. {"exception":"[object] (Nesk\\Rialto\\Exceptions\\ReadSocketTimeoutException(code: 0): The timeout (30.000 seconds) has been exceeded while reading the socket of the process. Maybe you should increase the \"read_timeout\" option. at /vendor/nesk/rialto/src/ProcessSupervisor.php:431, Socket\\Raw\\Exception(code: 11): Socket operation failed: Resource temporarily unavailable (SOCKET_EAGAIN) at /vendor/clue/socket-raw/src/Exception.php:55)
Describe the bug
It only takes screenshots what it sees without scrolling down.
Expected behavior
I want a full screenshot (for example to shot the parts where the user must scroll down).
I am just wondering if there is a way to stop the browser from closing automatically.
Currently, even if I do not call $browser->close();
the browser will close.
const args = [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-infobars',
'--window-position=0,0',
'--ignore-certifcate-errors',
'--ignore-certifcate-errors-spki-list',
'--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3312.0 Safari/537.36"'
];
const options = {
args,
headless: true,
ignoreHTTPSErrors: true,
userDataDir: './tmp'
}
const browser = await puppeteer.launch(options);
How could I pass the same options in puphpeteer? Need them in order for the scraper to work on most of my sites.
Hello,
Issue:
Tried passing a waitUntil option after a while there is an error.
Error Message:
Uncaught ExtractrIo\Rialto\Exceptions\Node\FatalException: Navigation Timeout Exceeded: 30000ms exceeded.
Code:
$page->waitForNavigation([ 'waitUntil' => 'networkidle0', ]);
Why was the waitUntil used:
Wanted to add in a wait as i am taking screenshots of a lot of pages and some screenshot does not
return the data for that page as it does not have time to load 100%.
Might be related not sure:
puppeteer/puppeteer#257
Might you have any other solutions to this issue?
Thank you in advance.
When calling puphpeteer by running the default example, a mighty error shows up. It wraps a js error: "Error: Cannot find module 'lodash' at Function.Module._resolveFilename".
To solve it run "npm install" in both "\vendor\nesk\rialto" and "\vendor\nesk\puphpeteer"
windows server 2016 standard
puphpeteer 1.3.0
node 10.10
php 7.2.8
npm
I want to run PHP on my host machine and run Node/Puppeteer in a Docker container. Has anyone attempted a workflow like that?
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:
Environment (please complete the following information):
My Node package manager is:
NPM 6.1.0
Hi, is there any way I can access the redirect chains thru puppeter?
$puppeteer = new Puppeteer([
'read_timeout' => 100,
'debug' => true,
]);
$browser = $puppeteer->launch([
'headless' => true,
'ignoreHTTPSErrors' => true,
]);
$page = $browser->newPage();
$response = $page->goto('http://invol.co/aff_m?offer_id=1664&aff_id=1024&source=deeplink_generator', [ 'waitUntil' => 'networkidle0' ]);
var_dump($response->request->redirectChain());
$browser->close();
I just manage to get null from the var_dump
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();
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.