带有 `unsafely-treat-insecure-origin-as-secure` 标志的 headless Chrome 上不一致的媒体设备行为
Inconsistent mediadevice behavior on headless Chrome with `unsafely-treat-insecure-origin-as-secure` flag
我正在 运行 与无头 Chrome 进行一些看似不一致的行为。我正在尝试使用 unsafely-treat-insecure-origin-as-secure
标志在 localhost
以外的域上使用无头 Chrome.
测试媒体设备
问题是当Chrome正常运行时,媒体设备按预期工作,但是当运行无头时,它们无法加载。
HTML 我正在测试 (media.html
):
<html>
<head>
</head>
<body>
<video id="video"></video>
<script>
navigator.mediaDevices.getUserMedia({audio: true, video: {width: 1280, height: 720}})
.then(function(stream) {
var video = document.querySelector('#video');
video.srcObject = stream;
video.onloadedmetadata = function() {
video.play();
};
}).catch(function() {
console.log("Failed to get media devices");
});
</script>
</body>
</html>
运行 Chrome 以下结果按预期工作:
chromium --unsafely-treat-insecure-origin-as-secure=http://lvh.me:8000 --use-fake-device-for-media-stream --use-fake-ui-for-media-stream --remote-debugging-port=9222 "http://lvh.me:8000/media.html"
使用 python2 -m SimpleHTTPServer 8000
作为网络服务器。
但是,运行ning Chrome 在无头模式下:
chromium --headless --unsafely-treat-insecure-origin-as-secure=http://lvh.me:8000 --use-fake-device-for-media-stream --use-fake-ui-for-media-stream --remote-debugging-port=9222 "http://lvh.me:8000/media.html"
然后转到 http://localhost:9222/
结果如下:
Uncaught TypeError: Cannot read property 'getUserMedia' of undefined
at media.html:9
有谁知道这种不一致是从哪里来的?为什么 headless Chrome 似乎不尊重 unsafely-treat-insecure-origin-as-secure
标志?
我正在 运行 与无头 Chrome 进行一些看似不一致的行为。我正在尝试使用 unsafely-treat-insecure-origin-as-secure
标志在 localhost
以外的域上使用无头 Chrome.
问题是当Chrome正常运行时,媒体设备按预期工作,但是当运行无头时,它们无法加载。
HTML 我正在测试 (media.html
):
<html>
<head>
</head>
<body>
<video id="video"></video>
<script>
navigator.mediaDevices.getUserMedia({audio: true, video: {width: 1280, height: 720}})
.then(function(stream) {
var video = document.querySelector('#video');
video.srcObject = stream;
video.onloadedmetadata = function() {
video.play();
};
}).catch(function() {
console.log("Failed to get media devices");
});
</script>
</body>
</html>
运行 Chrome 以下结果按预期工作:
chromium --unsafely-treat-insecure-origin-as-secure=http://lvh.me:8000 --use-fake-device-for-media-stream --use-fake-ui-for-media-stream --remote-debugging-port=9222 "http://lvh.me:8000/media.html"
使用 python2 -m SimpleHTTPServer 8000
作为网络服务器。
但是,运行ning Chrome 在无头模式下:
chromium --headless --unsafely-treat-insecure-origin-as-secure=http://lvh.me:8000 --use-fake-device-for-media-stream --use-fake-ui-for-media-stream --remote-debugging-port=9222 "http://lvh.me:8000/media.html"
然后转到 http://localhost:9222/
结果如下:
Uncaught TypeError: Cannot read property 'getUserMedia' of undefined
at media.html:9
有谁知道这种不一致是从哪里来的?为什么 headless Chrome 似乎不尊重 unsafely-treat-insecure-origin-as-secure
标志?