Chrome and Mocha Global Leaks - google-chrome

I have the following extremely simple Mocha / Chai test:
describe('main tests', function () {
var expect = chai.expect, something = null;
before(function () {
something = 0;
});
it('should equal 0', function () {
expect(something).to.equal(0);
});
});
This fails in chrome with the following output:
Error: global leaks detected: css, cssFile, cssRule
In both Firefox and Safari, it passes with no problem.
There was another global variable defined by Google's own Screen Capture extension. Upon disabling that extension Mocha only complained about css, cssFile, and cssRule being global leaks.
I checked and these variables are not defined in Safari or Firefox, so obviously something in Chrome or one of my Chrome extensions is defining these three variables. Is there any way to figure out which extension is defining these variables short of disabling and reenabling all of them in sequence?

The best solution for your problem is not some JavaScript snippet, but the source code of your installed extensions.
Visit the Extensions sub-directory of your Chrome profile (locations below).
Use a tool to recursively search for the term.
For example, using the grep command: grep -r 'cssFile' (available for Linux, Mac and even Windows).
Default locations for your profile's Chrome extensions
Windows XP:
Chrome : %AppData%\..\Local Settings\Application Data\Google\Chrome\User Data\Default\Extensions\
Chromium: %AppData%\..\Local Settings\Application Data\Chromium\User Data\Default\Extensions\
Windows Vista/7/8:
Chrome : %LocalAppData%\Google\Chrome\User Data\Default\Extensions\
Chromium: %LocalAppData%\Chromium\User Data\Default\Extensions\
Linux:
Chrome : ~/.config/google-chrome/Default/Extensions/
Chromium: ~/.config/chromium/Default/Extensions/
Mac OS X:
Chrome : ~/Library/Application Support/Google/Chrome/Default/Extensions/
Chromium: ~/Library/Application Support/Chromium/Default/Extensions/

Well, I just did the disable all extensions thing. Chrome Sniffer appears to be the culprit. Specifically in the following code (detector.js):
for (t in cssClasses) {
// snipped for brevity
for(css in cssClasses[t]) {
// snipped for brevity
for(cssFile in document.styleSheets) {
for(cssRule in document.styleSheets[cssFile].cssRules) {
// snipped for brevity
}
}
}
}
That will leak t, css, cssFile, and cssRule into global scope. Looks like I'm not the first to notice this: https://github.com/nqbao/chromesniffer/pull/51
If anybody wants to answer with how I could have avoided the manual process I will accept your answer.

Related

How to make WebGPU run in Chrome Canary 97?

Whichever WebGPU example (austin-eng, jack1232/WebGPU-Step-By-Step, etc...) I run in Chrome Canary 97.0.4686.0 with unsafe WebGPU flag enabled I get some errors in console that indicate that my browser does not support WebGPU.
Example: https://austin-eng.com/webgpu-samples/samples/helloTriangle
Is WebGPU Enabled?
TypeError: Cannot read property 'requestDevice' of null
Can you reproduce this behavior?
Recently (at least in 96), WebGPU is no longer behind a flag, instead it's now behind an origin trial. This means that you can register for a token and put it in the <head> of your webpage and it will enable WebGPU for all users.
To do this, go to: https://developer.chrome.com/origintrials/#/register_trial/118219490218475521, fill out the form, and retrieve your token. Note that you can also request a token for localhost for development. Then simply add <meta http-equiv="origin-trial" content={ORIGIN_TRIAL_KEY}/> to your webpage and if registered correctly, WebGPU will be enabled for not only you but everyone that visits your site.
If you are using JSX/React, use this: <meta httpEquiv="origin-trial" content={ORIGIN_TRIAL_KEY}/>
The difference is http-equiv vs httpEquiv.
As https://web.dev/gpu/#enabling-via-about:flags says, to experiment with WebGPU locally, enable the #enable-unsafe-webgpu flag in about://flags.
To check if WebGPU is supported, use:
if ("gpu" in navigator) {
// WebGPU is supported! 🎉
}
Caution: The GPU adapter returned by navigator.gpu.requestAdapter() may be null.
At the time of writing, WebGPU is available on select devices on Chrome OS, macOS, and Windows 10 in Chrome 94 with more devices being supported in the future. Linux experimental support is available by running Chrome with --enable-features=Vulkan. More support for more platforms will follow.
if you use chrome of canary, why not use the latest canary, as far as I know, satable version is already 108, the latest canary version is 111.
when you enable #enable-unsafe-webgpu in the lastest canary chrome. you can use ts code
let adapter: GPUAdapter;
let device: GPUDevice;
export async function getGpuDevice() {
if (device) {
return { adapter, device }
} else {
try {
adapter = (await navigator.gpu.requestAdapter())!;
device = (await adapter!.requestDevice())!;
} catch (e) {
alert('your browser don‘t support webgpu\n你的浏览器不支持 webgpu');
}
return { adapter, device };
}
}
good luck!

Proxy setting using chrome extension not working with chrome43

I am using chrome extension for switching the chrome proxy setting at runtime.
I have tested my code on chrome 59 and chrome 69 which is working fine.
However, the same code is failing when being tried upon chrome43.
The proxy is not getting switched and the requests are getting directly routed.
Do we have extension issues with chrome43?
Is there any other way to switch the chrome proxy at runtime without the need to restart the chrome browser?
let proxy = xx.xx.xx.xx; //intentionally masked for sharing code
let configPAC = {
mode: "pac_script",
pacScript: {
data : "function FindProxyForURL(url, host) { return 'PROXY "+proxy+"';}",
mandatory:true
}
};
chrome.proxy.settings.set({value: configPAC, scope: "regular"}, function() { console.log("Setting custom proxy here!");});

Cannot enable google chrome's flag "Experimental JavaScript" via command line/puppeteer

I'm using puppeteer-sharp and here is my browser creation code
Browser browser = await Puppeteer.LaunchAsync(new LaunchOptions {
Headless = false,
Args = new[] {
"--js-flags=\"--harmony\"",
"--flag-switches-begin",
"--enable-features=javascript-harmony",
"--enable-features=ExperimentalJavaScript",
"--enable-javascript-harmony",
"--flag-switches-end",
}
});
from that answer I read that --harmony V8 argument is enough for the needed flag to be enabled, but it isn't.
Although the arguments are passed
Flag is still not enabled
P.S. --enable-features=ExperimentalJavaScript, --enable-features=javascript-harmony and --enable-javascript-harmony I added myself making them by analogy to 1 2, not sure if these are correct usages (didn't found any documentation on this)
I am also unable to set flags when running google-chrome from command line google-chrome-stable --args --flag-switches-begin --enable-features=javascript-harmony --flag-switches-end

Webdriver.io enable flash for selenium-standalone

I'm writing acceptance tests on node.js using webdriver.io with selenium standalone server with latest Google Chrome driver.
I need to check that flash elements are clickable, but browser keeps to show me "Restart Chrome to enable Adobe Flash Player".
I've seen article that shows how to make Chrome driver to see custom profile on local machine, but I can't understand how to use this with my standalone server, since it has poor examples for configuration.
Can you explain the correct way to enable Adobe flash player for selenium standalone server in webdriver.io?
I found that the following worked:
browserName: 'chrome',
'goog:chromeOptions' : {
args: ['enable-features=RunAllFlashInAllowMode',
'disable-features=EnableEphemeralFlashPermission'],
prefs: {
"profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1,
'PluginsAllowedForUrls': '/route/to/site.com'
}
}
Using ephemeral mode will create a temp profile which allows the prefs to take effect:
https://developer.chrome.com/extensions/contentSettings
https://support.google.com/chrome/a/answer/3538894?hl=en
'goog:chromeOptions' was introduced as of selenium 3.8 github.com/elgalu/docker-selenium/issues/201 –
You can open up the profile which is a JSON blob and see the site added at profile.content_settings.exceptions.plugins and profile.content_settings.exceptions.flash_data.
It is very easy. you need to create a custom profile that you will always use to load your chrome with. then you configure the browser like you would do manually too. this means make website exclusions for flash. load some extensions or whatever you want to preconfig. with this code you can do it
// setup browser
var options = {
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['user-data-dir=C:/Users/Administrator/AppData/Local/Google/Chrome/User Data/Profile 21v69',
'--lang=en']
} // chromeOptions: {
} // desiredCapabilities: {
} // options = {
var client = webdriverio.remote(options).init();
Also here are all command line commands for chrome
https://peter.sh/experiments/chromium-command-line-switches/
Another workable method. It's possible to allow flash plugin execution in the chrome config
You need to add in the wdio.conf.js three last preferences from code example
chromeOptions : {
args: chromeArgs,
prefs: {
"download.default_directory": process.env.PWD +'/download',
"profile.default_content_setting_values.plugins": 1,
"profile.content_settings.plugin_whitelist.adobe-flash-player": 1,
"profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1
}
}
I hope it will helpful

Sahi OS Controller doesn't open with Chrome Version 24.0.1312.52 m

I have updated my chrome to Version 24.0.1312.52 m. Sahi OS controller doesn't open with the updated Chrome. I have checked the same with Alt, Alt+Ctrl, turned off popup blocker but still no luck. I checked the same on another machine and the same issue happened i.e. sahi controller doesn't open after updating chrome to the latest version.
OS: Windows 7 Pro
Browser: Chrome Version 24.0.1312.52 m
Sahi: Sahi OS version
Not sure what is going on, but here is the workaround.
Open sahi/htdocs/spr/concat.js
Look for Sahi.prototype.openControllerWindow.
Replace the full function so that it looks like:
Sahi.prototype.openControllerWindow = function (e) {
if (!e) e = window.event;
if (!this.isHotKeyPressed(e)) return true;
if (this._isChrome()) {
window.setTimeout(function(){_sahi.topSahi().openWin(e)}, 100);
} else {
this.topSahi().openWin(e);
}
return true;
};
Next search for _sahiControl in the same file and replace it with sahiControl. (You should see 2 occurrences.)
Restart Sahi, clear browser cache and check.
Regards,
Narayan
This has been fixed in Sahi 4.5.1. You can download it from this link: http://sahi.co.in/downloads-archive/
Thanks,