Chrome packaged app - find out if running in kiosk-mode - javascript

I'm creating an application that can be run both in kiosk mode and normally (like, open from Chrome browser) but certain features should only be allowed to run in kiosk mode. Is there a way I can find out if it's running in kiosk-mode or in normal fullscreen/windowed-mode?
Here's a snippet from my manifest.json if it's any help
{
"manifest_version": 2,
"kiosk_enabled": true,
"kiosk_only": false
}

From the documentation:
To determine whether the app is being run in a regular session or Single App Kiosk Mode, you can inspect the isKioskSession boolean that's included in the launchData object from the app.runtime.onLaunched event.
So:
chrome.app.runtime.onLaunched.addListener(function(launchData) {
launchData.isKioskSession; //true or false
});

Related

How to open browser with open console [duplicate]

I want to ask how to open the Chrome developer Console during selenium tests execution. Currently, when tests are executing, and I open the console manually hitting F12, the tests stop responding immediately and fails after some time.
Can anyone tell me how can I initiate my tests with developer console opened, so I can catch/observe the console errors that occur during test execution.
Use --auto-open-devtools-for-tabs:
This flag makes Chrome auto-open DevTools window for each tab. It is intended to be used by developers and automation to not require user interaction for opening DevTools.
Source
How to use
Note: this answer does not apply to current versions of Chrome.
You can't. The Chrome driver uses the Chrome remote debugging protocol to communicate with the browser. This is the same protocol that the developer console uses also. Unfortunately, Chrome is designed so that only one client can be attached using the protocol at a time, so that means either the developer tools, or the driver, but not both simultaneously.
Have you tried simulating the key press events for the shortcut of opening the dev tools in Chrome?
String openDevTools = Keys.chord(Keys.ALT, Keys.CONTROL, "i");
driver.findElement(By.ByTagName("body")).sendKeys(openDevTools);
This is not ideal and in a rigorous testing regime you would need platform detection to ensure you are covering both Mac and Windows. I would absolutely recommend avoiding this (even if it works), but it's a possible as a work-around if you really must.
I have a feeling it may also lose focus of the window itself if you do this. If this is the case, you'd need something like the following: -
String parentHandle = driver.getWindowHandle(); // get the current window handle
// do your dev tool stuff here
driver.switchTo().window(parentHandle); // switch back to the original window
Hope this helps.
Useful link if it does get you anywhere: How to handle the new window in Selenium WebDriver using Java?
Edit: Just re-read the question and don't think this will work anyway. Your unit tests should capture errors in the logic of your code. Your selenium tests should only test user journeys and capture errors when the user journey is cut short. You should never be testing code logic/error throwing through a selenium test.
This is working for me in webdriver.io (wdio.conf.js)
const configs = {
chrome : {
maxInstances: "5",
browserName: "chrome",
chromeOptions: {
args: ['--window-size=1280,800', '--auto-open-devtools-for-tabs'],
binary: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
}
},
firefox : {
maxInstances: "5",
browserName: "firefox"
},
headless : {
maxInstances: "5",
browserName: "chrome",
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=1280,800'],
binary: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
}
},
}

WebdriverIO automation testing when JavaScript is disabled

Is there a way in WebdriverIO framework to launch the browser with JavaScript disabled?
I want to automate a scenario with JavaScript being disabled. But, when I manually disable the JavaScript in Chrome, or Firefox and run the WDIO scripts, the browser always opens with JavaScript enabled.
Not anymore. (but you have a workaround below)
This used to be easily achieved using the chromium switches. But considering all driver implementations (chromedriver, geckodriver, etc.) now require JavaScript to drive your spawned browser instance, it's no longer possible.
It was achieved via chromeOptions arguments/switches:
capabilities: [{
maxInstances: 2,
browserName: config[env].browser,
chromeOptions: {
args: ['--disable-javascript',
'--disable-javascript-harmony-shipping'
]
}
}]
!!! LATER EDIT: You can achieve this by loading a custom profile.
Start your WebdriverIO test case, but add a browser.debug() after you load your page;
In the address bar, type chrome://settings/content and in the modal, check the Do not allow any site to run JavaScript. Click Done. Now go to a random page and notice JavaScript has been blocked on it:
Now we have to save this custom profile and load it each time you start a WebdriverIO test case. Type chrome://version in your address bar. Notice the Profile Path value. Copy the content of the folder (e.g.: For C:\Users\<yourUserName>\Desktop\scoped_dir18256_17319\Default, copy the scoped_dir18256_17319 folder on your Desktop). This folder contains all the actions (search history, extensions installed, accounts saved... in our case, JavaScript disabled option) on THIS current instance.
Now all we need to do, is add the path to that folder in your wdio.config.js file as a chromeOptions argument:
chromeOptions: {
//extensions: ['./browserPlugins/Avira-SafeSearch-Plus_v1.5.1.crx'],
args: [ '--user-data-dir=/Users/<yourUserName>/Desktop/scoped_dir18256_17319'
]
}
Now all you have to do is run your test cases with this custom profile and JavaScript will be blocked on all websites. Hope this is the behavior you are looking for as there is no other way to achieve this behavior.
Cheers!

Detect if another Chrome app is running

I've got a Chrome extension and a Chrome app, which can communicate with each other over messaging. There are certain actions I want the extension to take only when the Chrome app isn't running. Given the Chrome app's Id, how can I detect from the Chrome extension if it is running?
I've tried using closed and suspend lifecycle events from the chrome app to assist, but that route isn't seeming possible due to various reasons. Is there any other way to detect?
Well, you are already using Messaging, so presumably App's event page will wake up to answer if you call it, even if the app is not launched.
You define "running" as having windows open. From the event page, you can check that:
chrome.runtime.onMessageExternal.addListener(function(message, sender, sendResponse) {
/* ... */
if (chrome.app.window.getAll().length) {
// Launched
} else {
// Not launched
}
});
Something like:
chrome.management.get(appId,function(theapp){
if(theapp.enabled){
// it is running
} else {
// it is not running
}
});

How to add "open link in app mode" to right-click menu in chrome?

app mode: chrome window without navigation panel(address+tab bars). Run this in terminal
google-chrome --app=http://stackoverflow.com/
I want to open a website in app mode directly from chrome. Is there an extension that adds such option? If not how do I write a small extension that does just that? I never wrote a chrome extension but I have some experience with html and javascript. Thanks
Edit: Main issue is chrome.windows.create has no "app" option for CreateType. I guess we can't do anything about it.
There is a way using chrome.management API.
chrome.management.generateAppForLink("http://stackoverflow.com/", "Stack Overflow", function(info) {
chrome.management.setLaunchType(info.id, "OPEN_AS_WINDOW", function() {
chrome.management.launchApp(info.id);
})
});
Note that the above code requires a user gesture (which is undocumented). For examples, see Invoking activeTab. Activating a context menu should be sufficient as a gesture.
However, this will create an app in the app launcher permanently. On the plus side, it will not create duplicates for the same URL/Title.
You can call chrome.management.uninstall(id), but it will require a confirmation from the user.

Catching keyboard shortcut outside of a browser using a browser extension?

I have a project where I require a Push-to-Talk feature. I came to the conclusion that it may be do-able if I create an extension/plugin for Chrome/Firefox. The site is HTML5 based with WebRTC and I would like to implement a alternative plugin/extension users can download that will allow them to use push to talk outside of the browser. I.e. when the browser is minimized but the website is still open in the browser.
I want the plugin/extension to still listen for the keystrokes. Is this do-able? Or do I need to create an application the users can download where the application will make a hook into the websites webrtc API and allow the users to use Push-to-Talk? I would rather like to stay away from the users having to download a .exe and much rather them just able to install a plugin/extension for their Chrome or Firefox browsers.
It is doable in principle in Chrome, as you can define global shortcuts with chrome.commands:
Manifest:
"commands": {
"push-to-talk": {
"suggested_key": {
"default": "Ctrl+Shift+1"
},
"description": "Activate push-to-talk",
"global": true
}
},
Background:
chrome.commands.onCommand.addListener(function(command) {
if(command == "push-to-talk"){
// Do whatever you want, e.g. bring focus to browser,
// pass commands to page with content scripts etc.
}
});

Categories