iframe嵌套的https服务,权限开放设置

1、场景:

  chatGPT开发语音功能,部署服务需要https协议,有个独立的门户需要将服务以iframe嵌入到系统中

2、问题:

  chatGPT语音服务无法弹出授权开启麦克的提示

3、原因:

  iframe默认是关闭了相关权限

4、处理:

参考说明

<iframe>标签的 sandbox 属性是一个布尔属性,当存在时表示将在 iframe 内部加载的文档中禁用指定的功能。该属性支持以下几个值:

空值:默认情况下,没有禁用任何功能。
"allow-forms":         允许在 iframe 中提交表单。
"allow-pointer-lock":  允许通过 Pointer Lock API 锁定鼠标指针。
"allow-popups":        允许在 iframe 中打开弹出窗口。
"allow-same-origin":   允许在 iframe 中访问与父级页面具有相同来源的资源。
"allow-scripts":       允许在 iframe 中运行脚本。
"allow-top-navigation":允许在 iframe 中导航到新 URL。
可以使用空格或分号将多个值组合在一起,例如: <iframe src="example.com" sandbox="allow-forms allow-scripts"></iframe>

 <iframe>标签的 allow 属性是一个用于指定允许在 iframe 中使用哪些功能的属性。该属性接受一个由分号分隔的字符串,其中每个部分都是一个允许使用的功能。

以下是 allow 属性支持的不同功能:
accelerometer:      允许使用设备加速度计。
autoplay:           允许自动播放媒体(在某些浏览器中可能需要静音)。
camera:             允许使用相机。
encrypted-media:    允许解密受版权保护的媒体。
fullscreen:         允许进入全屏模式。
geolocation:        允许对用户位置进行地理定位。
gyroscope:          允许使用设备陀螺仪。
magnetometer:       允许使用设备磁力计。
microphone:         允许使用麦克风。
midi:               允许使用 MIDI 设备。
payment:            允许使用付款请求 API。
picture-in-picture: 允许视频以画中画方式显示。
speaker:            允许使用扬声器。
usb:                允许使用 USB 设备。
例如: <iframe src="example.com" allow="autoplay; camera; encrypted-media"></iframe>

综合以上参考最终配置:

<iframe id="chatifm" allow="encrypted-media; microphone; fullscreen"  />

 

posted @ 2023-07-17 10:05  【云】风过无痕  阅读(1305)  评论(0编辑  收藏  举报