Closed dongjian closed 2 years ago
by the way . is there any method can know when the webview is already load finish . I need to eval some js at the begining of the web. I tried the init method . but it not woring . I do it now like the code below
Message::WebServerAlready => {
println!("http server READY !");
wv.navigate("http://127.0.0.1:8080/map.html");
let sender = s.clone();
tokio::spawn(async move {
tokio::time::sleep(Duration::from_millis(100)).await;
sender.send(Message::SetDefaultMap);
});
}
Message::SetDefaultMap => {
let test = get_map_param_json(
None,
0.0,
"OpenStreetMap".to_string(),
);
wv.eval(&get_evl_str(test));
}
The webview doesn’t detect changes to files, you would need some notification system (like notify-rs) to notify the program of changes then reload the webview (call set_html or navigate). Regarding init, are you calling it before the set_html or navigate commands? What isn’t working? What OS?
OS: windows 10 Now I need to delete C:\Users\user\AppData\Local\Packages to clean the cache. Otherwise the WebView won't change . I use navigate
The webview doesn’t detect changes to files, you would need some notification system (like notify-rs) to notify the program of changes then reload the webview (call set_html or navigate).
Sorry , My english is not good . You may have misinterpreted my meaning .
<div>123</div>
<div>456</div>
How are you accessing map.html, is it via some GET request? In that case yes, caching happens in the webview’s system cache directory. You can use query strings or meta tags to disable caching during development: https://www.geeksforgeeks.org/how-to-clear-cache-memory-using-javascript/
Thanks.Because I deleted all the files in "AppData\Local\Packages" earlier. After I rebooted my computer. Calling webView crashes. So I re-installed the WebView2 Runtime for Windows(MicrosoftEdgeWebView2RuntimeInstallerX64.exe). Now even though I didn't use the method you mentioned above. Can work normally and update the page normally .So May be it's windows webview runtime bug.
I tried again. It doesn't refresh properly again.
<html>
<head>
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
<meta charset="UTF-8">
.........
<body>
<div id="root"></div>
<script type="text/javascript" src="map.js?version = 1.2"></script>
</body>
I do like the article . but it still load the cache. even if i delete the map.html
I checked the output of the server. Does not request my server when the cache exists
[2021-12-02T07:01:37Z INFO actix_web::middleware::logger] 127.0.0.1:50142 "GET /car.svg HTTP/1.1" 404 0 "http://127.0.0.1:8080/map.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.000226
[2021-12-02T07:01:37Z INFO actix_web::middleware::logger] 127.0.0.1:50142 "GET /favicon.ico HTTP/1.1" 404 0 "http://127.0.0.1:8080/map.html" "Mozilla/5.0 (Windows
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.000195
I have to change the filename to avoid the cache problem . after change the file name to 123.html 123.js . the server out put
[2021-12-02T07:10:01Z INFO actix_web::middleware::logger] 127.0.0.1:49689 "GET /123.html HTTP/1.1" 200 20150 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.006475
[2021-12-02T07:10:01Z INFO actix_web::middleware::logger] 127.0.0.1:49689 "GET /123.js?version=1.3 HTTP/1.1" 200 2992807 "http://127.0.0.1:8080/123.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.104495
[2021-12-02T07:10:01Z INFO actix_web::middleware::logger] 127.0.0.1:49689 "GET /car.svg HTTP/1.1" 404 0 "http://127.0.0.1:8080/123.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.000155
[],"baiduPosArr":[],"gSenserArr":[],"maxSpeed":0.0,"minSpeed":0.0,"distance":0.0},"dicNMEA":{}}
[2021-12-02T07:10:09Z INFO actix_web::middleware::logger] 127.0.0.1:49709 "GET /favicon.ico HTTP/1.1" 404 0 "http://127.0.0.1:8080/123.html" "Mozilla/5.0 (Windows
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41" 0.000155
I set up a file server locally. When I change the HTML content, the WebView does not change. (It works fine on the browser). Even if I delete the file, the WebView still works fine. I tried to restart the computer and delete target cargo run again ,but the cache was still there.I need to modify the file name, and then modify the url. Webview to appear the new content . any help?