Open dirkk0 opened 5 years ago
This user-gesture
policy is a broader issue of the Electron platform. Electron should have a different trust model (i.e. CORS, user-gesture
etc) than a simple website. I believe special flags / options should be supported to disable these "security" requirements. Below are several such use cases:
requestFullScreen
autoplay
click events - it seems Chrome require user interaction for them to be fired. This makes no sense for a remote controlled electron app for example (i.e. a TV app controlled via web sockets).
History API (pop events are not triggered without user interaction).
There are some related issues closed for various reasons. Chrome used to have a flag to disable user-gesture but we all well know that Chrome flags are treated as experiments/unstable so they removed them .
https://github.com/electron/electron/issues?q=is%3Aissue+user-gesture+is%3Aclosed
Bug Report
user gesture interaction (autoplay policy)
Problem
The main electron documentation states that
autoplayPolicy
defaults tono-user-gesture-required
which unfortunately isn't the case (see here and search for autoplay ). Actively setting it to"autoplayPolicy":"no-user-gesture-required"
in thewebPreferences
has no effect either.Fortunately this can be overcome by a hack described below.
What is expected to happen?
Sound is playing without a user interaction.
What does actually happen?
Sound is only playing with a user interaction.
Information
I wanted to document both problem and workaround in this issue.
The workaround is based on this part of the docs and this issue: Add
after
around line 23 of
platforms/electron/platform_www/cdv-electron-main.js
.This effectively adds a command line switch to Chromium.
Command or Code
Take the default cordova application, add the
cordova-plugin-media
and put this code in theonDeviceReady
method:The sound will play, but only if you click the window within the first seconds. If not, the console shows the infamous 'user interaction required' error.
Environment, Platform, Device
Mac OS 10.13.6 (High Sierra)
Version information
Cordova CLI
Checklist