Reply To: download web page content (html file) without opening a browser

Welcome! Forums Unity Plugins In-App Web Browser download web page content (html file) without opening a browser Reply To: download web page content (html file) without opening a browser

#2129
bruevp
Participant

Can you please give an example on how to “use javascript to fetch content of a website and pass it to your C# script” without opening a browser window?
It’s probably very simple, but I cannot figure it out without documentation
For now I only found a way to do it after page loads in a browser like this:

private string javaScriptCode = “UnityInAppBrowser.sendMessageFromJS(document.documentElement.outerHTML)”;

void Start() {
InAppBrowserBridge bridge = FindObjectOfType<InAppBrowserBridge>();
bridge.onBrowserFinishedLoading.AddListener(Execute);
bridge.onJSCallback.AddListener(OnMessageFromJS);
}

private void Execute(string command)
{
InAppBrowser.ExecuteJS(javaScriptCode);
}

void OnMessageFromJS(string jsMessage)
{
var filePath = Application.persistentDataPath + “/savedPage.html”;
File.WriteAllText(filePath, jsMessage);
}