开发者

Safari extension that spoofs user-agent?

开发者 https://www.devze.com 2023-01-23 17:53 出处:网络
Is it possible to spoof the user agent using a Safari extension? I know that Safari itself is able to spoof using the Develop menu item, but it\'s to开发者_开发问答o limited for me.

Is it possible to spoof the user agent using a Safari extension? I know that Safari itself is able to spoof using the Develop menu item, but it's to开发者_开发问答o limited for me.

As far as I know, Safari extensions use 'start' and 'end' scripts, but both are executed after the document has been loaded, so I can't use those scripts to change the user agent via JavaScript.

I'm not too sure about this, only started looking into extensions today, so maybe someone has another idea?


If you just looking for a way to quickly change between User Agents in Safari, you might beable to use Applescript UI Script. Basically it can simulate almost any user interface click/type, which would allow fairly quick changing of User Agents.


If you go the AppleScript UI Scripting route, as mentioned by Kendal, you can change the User Agent by the name they shown on Safari’s menu:

tell application "Safari" to activate
tell application "System Events"
    tell process "Safari"
        click menu item "Safari — iOS 10 — iPad" of menu "User Agent" of menu item "User Agent" of menu "Develop" of menu bar item "Develop" of menu bar 1
    end tell
end tell
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号