Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Added useragent option to background webview
Browse files Browse the repository at this point in the history
Example JSON

```json
"body": {
            "background": {
                "type": "html",
                "url": "http://google.com",
                "options": {
                    "useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"
                },
                "style": {
                    "background": "#ffffff",
                    "progress" : "rgba(0,0,0,0)"
                },
                "action": {
                    "type": "$default"
                }
            }
        }
```
  • Loading branch information
clsource authored Sep 10, 2021
1 parent 0151815 commit b3cf3f5
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,33 @@ public void onFinished(JSONObject reduced_action) {
settings.setAllowFileAccess(true);
settings.setAppCacheEnabled(true);
settings.setCacheMode(WebSettings.LOAD_DEFAULT);

// Check for special options in background webview
/* Example JSON
"body": {
"background": {
"type": "html",
"url": "http://google.com",
"options": {
"useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"
},
"style": {
"background": "#ffffff",
"progress" : "rgba(0,0,0,0)"
},
"action": {
"type": "$default"
}
}
}
*/
if (options.has("options")) {
// Allows custom user agent for the webview
if (options.getJSONObject("options").has("useragent")) {
Log.d("Debug", "Using custom user agent: " + options.getJSONObject("options").getString("useragent"));
settings.setUserAgentString(options.getJSONObject("options").getString("useragent"));
}
}

// 2.2. Create and Attach JavaScript Interface
JasonAgentInterface agentInterface = new JasonAgentInterface(agent, context);
Expand Down

0 comments on commit b3cf3f5

Please sign in to comment.