Disable Chrome clipboard popups WebdriverIO - javascript

I'm trying to disable the chrome clipboard popup/notification using webdriverIO (Selenium) for automation. I tried setting chrome options but still it doesn't disable it. I want to click a web element that is behind this popup, so I don't want this popup to appear in automation. I tried disabling the clipboard settings manually but selenium opens a new session every time which refreshes the settings. Also, it is not possible to inspect using developer tools. It is not an alert so accepting/dismissing alert does not work either.
browser.alertAccept();
or
browser.alertDismiss();
chromeOptions: {
args: [
'disable-infobars',
'disable-popup-blocking',
'disable-notifications'
],
prefs: {
'profile.default_content_settings.popups' : 2,
'profile.default_content_settings.notifications' : 2,
}
}
Please help me with this issue, any help would be really appreciated.

A workaround might be to switch to the popup and dismiss it.
driver.switchTo().alert().dismiss();
or
driver.switchTo().activeElement().dismiss();
EDIT: I found an interesting Website. Try the code at the end of this site: http://blog.amolchavan.space/block-push-notification-on-chrome-in-selenium-webdriver/

I see many people also suggest to use profile.default_content_settings so it may be depend on chrome version. Current chrome version will work with this code as follows
chromeOptions: {
prefs: {
'profile.managed_default_content_settings.popups' : 2,
'profile.managed_default_content_settings.notifications' : 2,
}
}

After hours of trying, this worked for me with version 103 of Chrome (Jul 2022):
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.content_settings.exceptions.clipboard": {
'*': {'setting': 1}
}}
chrome_options.add_experimental_option('prefs', prefs)
...
currentDriver = webdriver.Remote(command_executor=SELENIUM_URL, options=chrome_options)
with currentDriver as driver:
...

Related

Exception Using chrome.desktopCapture.chooseDesktopMedia

In Chrome Manifest V2 I was able to easily capture the desktop. Attempting this in Manifest version 3 I have had no luck. I feel I may be missing something here in attempting this in Manifest V3.
I have been using this as a reference. https://developer.chrome.com/docs/extensions/reference/desktopCapture/
My manifest has these permissions granted to it
"permissions": [
"idle",
"tabs",
"storage",
"notifications",
"alarms",
"desktopCapture"
],
This is the sample code I have been testing just to see if I can get the screen selector to come up. I have not included the tabs.tab as this is labeled as optional and I wanted to see if I could have the plugin trigger the screen recording feature on its own.
chrome.desktopCapture.chooseDesktopMedia(["screen"], (streamID, options) => {console.log(id)});
I have been attempting to have this run in my background.js file.
Each time it runs chrome crashes completely with no errors given.
Reviewing the crash dump I can see the following information.
Exception Code: 0xC0000005
Exception Information: The thread tried to read from or write to a virtual address for which it does not have the appropriate access.
I solve it this way for Manifest v3.
It was giving me errors too. When I checked the documentation, chooseDesktopMedia it wanted three parameters.
DesktopCaptureSourceType[]
Tab
Callback Function
I see in your question your have put 1 and 3. I did the same it was giving me errors. So I made sure I get the active tab first before calling chrome.desktopCapture.chooseDesktopMedia in the background script.
So the code looks like this
chrome.tabs.query({ active: true }, (tabs) => {
if (tabs.length) {
const tab = tabs[0];
var pending = chrome.desktopCapture.chooseDesktopMedia(["window"], tab, (streamId) => {
//console.log(streamId, tab);
});
}
return false;
})
And it worked. I hope this helps

Selenium WebDriver — Start Chrome with DevTools open to Console panel

I know how to start Chrome with the DevTools open so please don't tell me it is a duplicate of How to open Chrome Developer console in Selenium WebDriver using JAVA
I'm trying to have the DevTools open to a specific panel. By default it opens on the Elements panel but I want it to open on the Console panel instead:
I've seen this command line switch --devtools-flags but I haven't found any example usage of it. Essentially what I'm trying to achieve is something similar to that. Obviously that doesn't work but you get the gist:
const { Options } = require('selenium-webdriver/chrome');
// …
const options = new Options().addArguments([
'auto-open-devtools-for-tabs',
'devtools-flags="panel=console"' /* <- That doesn't work. What else would? */
]);
// …
I figured out how to do this for my Ruby on Rails app that uses RSpec and Capybara. Here's the code that I use to configure my Capybara driver to select the Console tab and dock the devtools to the bottom:
options = Selenium::WebDriver::Chrome::Options.new
options.add_preference(
'devtools',
'preferences' => {
'currentDockState' => '"bottom"', # Or '"undocked"', '"right"', etc.
'panel-selectedTab' => '"console"',
}
)
...
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options,
desired_capabilities: capabilities,
You should be able to call the setUserPreferences function to set user preferences: https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/chrome_exports_Options.html#setUserPreferences
const { Options } = require('selenium-webdriver/chrome');
// …
const options = new Options().addArguments([
"auto-open-devtools-for-tabs"
]).setUserPreferences({
"devtools": {
"preferences": {
"panel-selectedTab": "\"console\""
// "currentDockState": "\"bottom\"" // Or "\"undocked\"", "\"right\"", etc.
}
}
});
(I haven't tested this for JS, so please try it out and let me know if it works.)
I figured out how to set these preferences by looking at ~/Library/Application Support/Google/Chrome/Default/Preferences. This is where my main Google Chrome installation stores my user preferences, and it's JSON data.
You can view all of the possible settings under devtools => preferences. Note that all the values are strings that are parsed as JSON, so you need to "double-wrap" any strings in your code, e.g. "\"console\"".
You can open your main Google Chrome browser and change the settings in the UI, and then re-open your Preferences file to see what JSON you need to set.

chrome.declarativeContent.PageStateMatcher conditions not

I'm starting to learn how to develop a chrome extention (manifest 3) and I have some result I don't understand.
My final goal is to get the cookie value when a specific website is open, to send a request to this web site (fetch) and to show the json received in a new tab (I developed a javascript to send the request and it's working but I now want to get the cookie automaticaly with a chrome extention).
To start my learning, first step is to open a new tab when I'm on the website. I tried the below code in my background.js but the new tab is created when I activate my extention even if the website is not open and no new tab created after even if my condition is ok. Then I think I missed something but I don't knwo what.
Could someone explain me why, where I'm wrong and if not the good way, which chrome API I should see ?
chrome.runtime.onInstalled.addListener(function () {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function () {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: "www.google.com", schemes: ["https"] },
}),
],
actions: [chrome.tabs.create({})],
},
]);
});
});
Your code actions: [chrome.tabs.create({})] is wrong. The method chrome.tabs.create will be called when the extension installed. Maybe you want to trigger your popup.html when clicking the extension. If so, you can use actions: [ new chrome.declarativeContent.ShowPageAction() ]. Then use chrome.action.onClicked.addListener, see here.
If you want to automatically open a new tab when some website is opened, you can use chrome.tabs.onCreated.addListener, see here, handle the event, filter the url, then do sth.

Is there any way to get the real url from the omnibox when on a chrome error page?

I am currently trying to make an extension that will auto unsuspend tabs that used to be suspended with the great suspender.
function unsuspend() {
if(document.location.href.startsWith("chrome-extension") &&
document.location.href.indexOf("/suspended.html#") > -1) {
unsuspendurl = document.location.href.substr(document.location.href.lastIndexOf("&uri=")+5);
return unsuspendurl;
}
}
The problem is that when an extension is uninstalled you get an error page that is the document (chrome-error://chromewebdata/).
I have tried to find if anyone has a way to get the omnibox text but no luck.
I think extensions can't access other extensions pages. So I had to do this semi-automatically in my attempt to solve this :) https://gist.github.com/JLarky/0385d22305c86ed5ca05b254a1e902ac

Firefox Add-on SDK : equivalent to Chrome "chrome_url_overrides"

I'm making add-on modules for several browsers, including Chrome and Firefox.
I just did what I want with Chrome : overriding new tab url to load a HTML file with the manifest.json. Pretty simple. (Now I'm able to copy paste again :)) :
...
"chrome_url_overrides" : {
"newtab": "override.html"
},
...
When the user create a new blank tab, it overrides the default page and loads the file I want : override.html, with the same behavior (no URL in the address bar).
But now, I want to do the same thing with Firefox using Add-on SDK. I tried using browser.newtab.url :
var { get, set } = require("sdk/preferences/service");
var { when: unload } = require("sdk/system/unload");
var oldValue = get("browser.newtab.url");
set("browser.newtab.url", 'http://www.example.com');
// Restore old setting when unload
unload(function() {
set("browser.urlbar.autoFill", oldValue);
});
It works, but I really would be able to load an HTML file instead giving it a new URL (the code would be more maintainable) and keep a clean address bar.
Any ideas ?

Categories