Using extensions on Chromium with Puppeteer - web-scraping

I'm trying to automate a buying process but I need to have a specific extension active. The extension itself doesn't need to be automated.
Is there a way to activate that extension on Chromium dev mode?
Or is there a way to open my normal Chrome session with all my extensions?
Thanks in advance!

You should be able to do it through a Chromium > 8.0.0. You can specify an args option through the class: Puppeteer, puppeteer.launch().
Condition
Description
--load-extension
Comma-separated list of paths to extensions to load at startup.
let browser = await puppeteer.launch({
//...
ignoreDefaultArgs: [
//...
"--disable-extensions",
args: [
//...
`--load-extension=${PATH_TO_EXTENSION}`
],
});
Alternatively, you could run Chrome instead of Chromium.
executablePath is a puppeteer.launch() option that let you set a path to a browser executable to run instead of the bundled Chromium.
Option
Description
executablePath
String Path to a browser executable to run instead of the bundled Chromium. If executablePath is a relative path, then it is resolved relative to current working directory. BEWARE: Puppeteer is only guaranteed to work with the bundled Chromium, use at your own risk.
https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#puppeteerexecutablepath

Related

Blazor WebAsssembly client app does not refresh and does not use the latest code

How can I make sure that the users of a Blazor client app always load the latest version of the code? I now have to instruct them to clear their browser caches every time a new version is published. This hampers the "release early and often" approach and I simply cannot believe that any serious blazor development is at all possible without checking for new versions at start up (what click once applications do).
I found this solution on https://learn.microsoft.com/en-us/answers/questions/214424/blazor-wpa-not-updating.html
/**
* Register Service Worker
*/
navigator.serviceWorker
.register('/***.js', { scope: '/' })
.then(() => {
console.log('Service Worker Registered');
});
This js file can contain a cache version like below.
const CACHE_VERSION = 1.0
But that is too cryptic for me? How can I implement the solution stated above as in "for dummies"?
The answer is (once you know it) quite simple:
In the index.html under the wwwrootfolder you will find:
<script>navigator.serviceWorker.register('service-worker.js');</script>
Below this write:
<script>navigator.serviceWorker.register('version.js');</script>
And create a "version.js" file in this folder with as single content:
const CACHE_VERSION = 1.0
Increment the 1.0 value each time you want your clients to load the new version.
It looks like this:
Once your clients have managed to clear their cache and load the version that contains this code, a simple reload or shut down and restart of the browser will make the new version active.

How to change default download location of chrome browser using robot framework

I am new to automation and currently using Robot framework. I am trying to change the download location of the browser when running the tests. I tried below code and doesn't work
${kwargs} Create Dictionary download.default_directory=C:\\
create webdriver ${G_BROWSER} ${kwargs}
You can use below code
${DownloadFile}= Get File ${DownloadPath}
You can give download path(${DownloadPath}) as your wish, automatically, file will be save in that path
${path}= Set Variable ${downloadPath}
Create Directory ${path}
${CHROME_OPTIONS}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${prefs} Create Dictionary download.default_directory=${path}
Call Method ${CHROME_OPTIONS} add_experimental_option prefs ${prefs}
Create Webdriver Chrome chrome_options=${CHROME_OPTIONS}
Use the updated suggestion for changing the download directory in the selenium library of Robot Framework.
Instead of using Create WebDriver - the Robot Framework team suggested using Open Browser Keyword to change the download directory
${prefs} = Create Dictionary download.default_directory=C:\\Balaji
Open Browser https://www.google.com/ chrome
options=add_experimental_option("prefs",${prefs})
Maximize Browser Window
Set Browser Implicit Wait 20

Access a Meteor App's unique .id

I'm writing a Meteor package that needs to know the id of the app that includes it -- the value that is saved in the .meteor/.id file relative to the project directory.
How can I access the id safely in development AND in production?
This is doable from server-side code using NPM. I just tested the following on my local project and it works:
// server-side code
// FYI, Npm.require works in packages only. Use meteorhacks:npm to use
// in non-package code. In meteor shell you can just use `require`.
var fs = Npm.require('fs');
var path = Npm.require('path');
var idPath = path.join(process.env.PWD, '.meteor/.id');
var fileContent = fs.readFileSync(idPath);
var fileContentLines = fileContent.toString().split('\n');
// this will contain the ID
var theId = fileContentLines[fileContentLines.length - 2];
Now, keep in mind that in production, you don't have the .meteor directory. After running a grep for the id in the build folder, it seems to me like that ID is not stored in any file within the build. Therefore, you will need to create a build plugin which makes sure to make it accessible somewhere during the build process. I may not have looked hard enough, so I would definitely take a look at the source for the build tool and see what it does with that ID during build.
In Meteor 1.2.1, (and 1.3) the appId is accessible via the __meteor_runtime_config__.appId variable on the client and server in development mode. This is undocumented so we don't know if it will be available in future versions.
The .appId property of __meteor_runtime_config__ is NOT available:
In production mode (when Meteor.isProduction)
In test mode (when Meteor.isTest)
In app test mode (when Meteor.isAppTest)
How about using Meteor Settings file http://docs.meteor.com/#/full/meteor_settings? It should be the right way to do that, Otherwise you will have to use Node.js to access the file directly

Easy way to handle developemnt/production URLs in flex air app

Easy way to handle developemnt/production URLs in flex air app? I want to point to my local box for testing, but when I launch I want it to automatically point to the production URL.
You can use namespaces and configure the current namespace (DEV/RELEASE) in your compiler options.
CONFIG::release
public function connect()
{
//connect to release url
}
CONFIG::dev
public function connect()
{
//connect to dev url
}
then define these options for the compiler:
-define=CONFIG::release,false
-define=CONFIG::dev,true
I suggest either using a configuration file or changing your hosts file to point domains to localhost or dev servers on your development machine. With the latter option you always use your production URLs in code, but your dev machine will resolve those domains to your local machine because it checks the hosts file first.
The best approach here is to externalize this information into a config file - perhaps an XML file - that is loaded via a relative url. The config file might like look this:
<config>
<serviceEndpoint>http://www.mydomain.com/services</serviceEndpoint>
</config>
Be sure to name your XML elements with valid ActionScript variable names or you may encounter some difficulty working with the file (for instance, E4X expressions may become difficult.
You can then use HTTPService to load "config.xml" which is placed alongside your application's SWF when deployed. This will allow you to repoint a SWF hosted on any domain to backend hosted anywhere else. This is especially useful if you are developing locally and are connecting to a shared development server.
Compiling this information into your SWF is very inflexible and a poor practice.
I typically will look at the url in the contentLoaderInfo object in either the Application (Flex -- http://livedocs.adobe.com/flex/201/langref/mx/core/Application.html#url) or root display object (Flash -- http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html#url). If the url begins with "file", you know you are in your development/IDE, if it's "http", it's being run in a browser. If you're just working in the browser, you might also pass a parameter to the object that has something like
{
url: $_SERVER['SERVER_NAME'];
}
and perform some init/startup method to switch based on the path the app is running under.
I had this very issue in an AIR app I am writing that hits a Rails app via WebORB.
I just need to switch between http://localhost and http://fakeproductionurl.com depending on whether I was running in Flex Builder (via adl).
This is what I ended up using:
if (NativeApplication.nativeApplication.publisherID != "") {
return "http://fakeproductionurl.com";
}
else {
return "http://localhost";
}
It doesn't give you the ability to switch between 3+ different environments, but it's a very easy way to toggle between development / production environments.

Detect from browser if specific application is installed

We have an advanced webpage (ASP.NET, C#), and a application which needs to be installed on the client computer in order to utilize the webpage to its fullest. The application is a tray app, and has primarily two tasks. Detect when certain events happen on the webserver (for instance invited to a meeting, or notify of an upcoming meeting). The other task the trayapp has is to use a custom protocol (trayapp://) to perform some ajax calls back to the server.
One problem we have is how to determine if the application is installed on the local machine or not. Now the user has to tick a checkbox to inform the website that the application is installed, and that it's safe to call the trayapp:// url calls.
Is there any way, for instance through a JavaScript or similar to detect if our application is installed on the local machine?
The check needs to work for IE, FF and Opera browsers.
When installing your client-side app you could modify the browser configuration to include another request header in HTTP requests and then have the server code look for that header, for example as a supported mime type using the following registry key (for Internet explorer)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\
Internet Settings\Accepted Documents
I am not sure if Opera and FF use this same key, but they likely have similar configuration options, but this should at least get you on the right track.
If you want to detect with javascript inside the browser, you can probably use the collection "navigator.plugins". It works with Firefox, Opera and Chrome but unfortunately not with IE.
Update:
In FF, Opera and Chrome you can test it easily like this:
if (navigator.plugins["Adobe Acrobat"]) {
// do some stuff if it is installed
} else {
// do some other stuff if its not installed
}
Update #2:
If it is an ActiveX object in IE you can test if it exists by using something like this:
function getActiveXObject(name){
try{
return new ActiveXObject(name);
}
catch(err){
return undefined;
}
};
Another approach for IE is something similar to what JohnFx suggested (I found it here and have not tested it):
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Internet
Settings\User Agent\Post Platform
Good idea from #JohnFx.
Another way to tackle this would be to install an ActiveX control or Browser plug-in with the trayapp installation. You could then access this in a similar way to that done when checking the version of Flash available.
Expose the trayapp (assuming this as a Managed app) as COM object. You could then use the tag with the GUID and trap errors when not found or use the ActiveXobject with the progid to detect if it's installed.

Resources