我正在制作一个 Electron 桌面应用程序,试图模拟谷歌设备工具栏,如果我使用 iframe,我会得到所需的行为,网页填满整个屏幕,(没有水平滚动条),但是我不能嵌入具有相同来源的网站策略,另一方面,webview 可以显示这些网站,但我无法模拟设备的高度和宽度,对于较小的设备,只有部分网页可见,您必须水平滚动才能看到页面。有没有办法解决 ?
最佳答案
有点晚了,但这里有一个解决方案(如果我理解正确?):
<webview src="https://instagram.com/direct/inbox" useragent="Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko; googleweblight) Chrome/38.0.1025.166 Mobile Safari/535.19"></webview>
或者
const webview = document.querySelector('webview')
webview.useragent = "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko; googleweblight) Chrome/38.0.1025.166 Mobile Safari/535.19"
webview.src = 'https://instagram.com/direct/inbox'
额外信息:
Electron useragent
List of User Agents
确保您使用 webviewTag
webPreferences: {
nodeIntegration: true,
webviewTag: true
}
关于html - electron webview 模拟手机屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59040019/