electron builder puppeteer missing local chromium - puppeteer

Is used the two packag.json structure to load dependencies in electron builder config.
"build": {
"asar": true,
"asarUnpack": "node_modules/puppeteer/.local-chromium/**/*",
"appId": "client.zpa",
"directories": {
"output": "./dist-exec",
"app": "."
},
"win": {
"target": [
{
"target": "nsis",
"arch": [ "ia32" ]
}
]
},
"nsis": {
"artifactName": "${productName}_${version}1231.${ext}"
}
...
"dependencies": {
"serial-number": "1.3.0",
"puppeteer": "~1.15.0",
"hummus": "~1.0.104"
}
in dist/node_modules/puppeteer the folder .local-chromium is missing. Any ideas how I can force installing local chromium?

I had the same problem.
Solved via downloading chromium according to current OS (Windows/Linux/Mac OS) on first start.
And, if there is Google Chrome browser available on running machine, you can pass path to chromium in puppeteer config.
Something like this on Windows C:\Program Files (x86)\Google\Chrome\Application\chrome.exe or run this
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep -i "google chrome"
on Mac OS to find path to Google Chrome.
I've heard that it is possible to use Electron IPC and that calls into the JavaScript boot file and then run puppeteer from there.
But haven't tried.

After 2 days of searching on StackOverflow and GitHub issues, I found that no actual solutions to build the local chrome with the electron app the best solution was to set the executable path and use chrome installed on the pc but many answers said that You will do it manually but I found this better to do it using "chrome-path" npm package to set path of chrome auto in mac or Linux or Windows here it's my code background.js
const puppeteer = require("puppeteer")
const chromePaths = require('chrome-paths');
//your electron init window
const browser = await puppeteer.launch({
executablePath:chromePaths.chrome,
headless: false,
defaultViewport: null,
args: ['--no-sandbox', '--start-maximized' ],
slowMo:25,
})
const page = await browser.newPage();
await page.goto("https://google.com")
await app(page)
`

Related

How do I use puppeteer core with google chrome extensions?

I want to run a basic script that takes a screenshot of the tv schedule each day on a specific url, the url in question has a cookies pop up that requests to be accepted before the rest of the page is displayed, this obviously gets in the way of my intended screenshot, a similar post (Pupeteer - how can I accept cookie consent prompts automatically for any URL?) had a solution that suggested to download the chrome extension 'I don't care about cookies' and then run puppeteer with google chrome with this extension installed, I have installed the extension and ran puppeteer with chrome but the extension does not seem to show up in the chrome window that puppeteer creates, how do I fix this so the extension is there when I run chrome using puppeteer? note: I am intentionally using regular chrome not chromium for this reason, chromium does not allow extensions with puppeteer.
my code:
const puppeteer = require('puppeteer-core')
async function main() {
const browser = await puppeteer.launch({
headless: false,
slowMo:10,
executablePath: '/Applications/Google
Chrome.app/Contents/MacOS/Google Chrome',
args: [
'--disable-extensions-except=/Applications/Google
Chrome.app/Contents/MacOS/Google Chrome',
'--load-extension=/Applications/Google
Chrome.app/Contents/MacOS/Google Chrome',
]
});
const page = await browser.newPage()
await page.setViewport({
width: 980,
height: 480,
deviceScaleFactor: 2,
});
await
page.goto("https://www.tvguide.co.uk/mobile/channellisting.asp?
ch=145#588622936")
await page.waitForTimeout(15000); // wait for 15 seconds
await browser.close()
}
main();
Any reply would be greatly appreciated. Many Thanks.

Windows 10 - running a puppeteer script opens a blank Chromium window

I am new to Puppeteer and am trying to run the example script. However, I get a blank chromium window (with no tab or URL bar).
Environment details:
OS: Windows 10
Node version: 8.4.0
NPM version: 6.4.1
I installed puppeteer using NPM and version 1.0.0 got installed. I also installed version 1.9.0 directly from Puppeteer's github page. Both versions have a similar issue.
This is my script:
const puppeteer = require('puppeteer');
(async () => {
try {
console.log('starting');
const browser = await puppeteer.launch({
executablePath: 'D:/Code/Puppeteer/node_modules/puppeteer/.local-chromium/win64-594312/chrome-win/chrome.exe',
headless: false
});
console.log('one');
const page = await browser.newPage();
console.log('two');
await page.goto('https://github.com');
console.log('three');
await page.screenshot({path: 'example.png'});
console.log("Page is up");
await browser.close();
}
catch (e) {
console.log("Error: ", e);
}
})();
In above script, I can see 'starting' and then Chromium window opens with nothing on screen. When I press F12 to bring up the dev tool, I see 'one' being printed on screen.
I have set environment variable 'path' to use this:
D:\Code\Puppeteer\node_modules\puppeteer\.local-chromium\win64-594312\chrome-win; C:\Program Files (x86)\Google\Chrome\Application
The puppeteer script is working now. I started the node.js cmd window in admin mode to run the script which did not work. Running in normal mode worked.

Protractor/Selenium embedded credentials dropped support for chrome

I am currently managing a staging environment with some authentication.
I was able to run my tests by embedding credentials to URL like this:
https://johndoe:foobar#app.s.product.com/#login
However, my tests fail because of chrome, dropping this feature(https://www.chromestatus.com/feature/5669008342777856). Is there any other way I can access our staging site? I tried inspecting the popup for credentials and maybe I can sendKeys(), but to no avail.
Thanks in advance!
Have this problem too. My solution is creation chrome extension and add it to chrome on startup.
Create two files in some new folder:
background.js (change user and path with yourth)
chrome.webRequest.onAuthRequired.addListener(
function(details, callbackFn) {
console.log("onAuthRequired!", details, callbackFn);
callbackFn({
authCredentials: {username: "user", password: "pass"}
});
},
{urls: ["<all_urls>"]},
['asyncBlocking']
);
manifest.json
{
"manifest_version": 2,
"name": "Authentication for tests",
"version": "1.0.0",
"permissions": ["<all_urls>", "webRequest", "webRequestBlocking"],
"background": {
"scripts": ["background.js"]
}
}
Pack them into crx (chrome://extensions/ -> Pack extension)
Add this file to project
Add to conf.js:
As first line
var fs = require('fs');
const ext64 = fs.readFileSync('./ext.crx', 'base64');
exports.config = {
...
and to chrome options
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox'],
extensions: [ext64]
}
},

Selenium WebDriver (Ruby): How to download PDF files?

When running WebDriver (Ruby) using Chrome, what are the specific command-line switches or desired_capabilities to disable Chrome's built-in PDF viewer.
In other words, how does one programmatically configure Chrome to download PDF files rather than open using its internal PDF-viewer plugin?
Updated answer: Chrome 61 : Ruby 2.3 : ChromeDriver 2.32.498537
download_prefs = {
prompt_for_download: false,
default_directory: 'desired/download/path'
}
plugin_prefs = {
always_open_pdf_externally: true
}
options = Selenium::WebDriver::Chrome::Options.new
options.add_preference(:download, download_prefs)
options.add_preference(:plugins, plugin_prefs)
driver = Selenium::WebDriver.for :chrome, options: options
Based on the following resource provided Save PDF instead of opening in Selenium, I found this worked as desired
prefs = {
plugins: {
plugins_disabled: ['Chrome PDF Viewer']
},
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: 'desired/download/path'
}
}
browser = Selenium::WebDriver.for :chrome, prefs: prefs
There must be no trailing slash in the directory path

Chrome args and prefs don't seems to be work in protractor conf

Need help with below issues. I have work around for issue 1 so any tips on issue 2 would be great:
--start-maximized won't trigger full window so my current work around is adding below line in beforeEach function:
browser.driver.manage().window().maximize();
Trying to download file to default directory but the file is just going to download folder on my C drive instead of /tmp/downloads (on another drive).
My config:
capabilities: {
'browserName': 'chrome',
'chromeOption': {
args: ['--lang=en', '--start-maximized'],
prefs: {
'download': {
'prompt_for_download': false,
'default_directory': '/tmp/downloads',
},
},
},
},
As for download, I'm currently using solution from here.
There is a typo. It should be chromeOptions, not chromeOption.
I think the options in protractor conf have been updated to be without "--".
So perhaps try without "--"?
args: ['lang=en', 'start-maximized']