本文介紹了如何設置電子用戶代理的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我需要在電子中設置 UserAgent 以包含 touch
標志,因為我正在為觸摸屏編寫應用程序,并且它似乎沒有自動檢測到它正在觸摸屏上運行.
I need to set the UserAgent in electron to include the touch
flag since I am writing the application for touch screens and it doesn't seem to auto detect that it is running on a touch screen.
任何幫助都會很好,我已經嘗試在 BrowserWindow.loadURL 選項參數中設置它.
Any help would be nice, I already tried setting it in the BrowserWindow.loadURL options param.
推薦答案
可以在主進程中使用onBeforeSendHeaders:
import { session } from 'electron';
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
details.requestHeaders['User-Agent'] = 'SuperDuperAgent';
callback({ cancel: false, requestHeaders: details.requestHeaders });
});
這篇關于如何設置電子用戶代理的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!