I want to manipulate css and elements with JavaScript via using Tauri APP.
Here some images of source code and etc:
index.html
<!DOCTYPE html>
<html>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
}
</style>
<body>
<h1>Loading...</h1>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
script.js
location.replace('https://web.whatsapp.com');
window.onload = () => {
document.body.addEventListener("click", handleGroupChatNames);
function handleGroupChatNames() {
if (document.querySelector("._2gzeB")) {
if (document.querySelectorAll("._1BUvv"))
document.querySelectorAll("._1BUvv").forEach((element) => {
let str = element.textContent;
if (element.textContent.charAt(0) === "+") {
element.textContent = str.replace(
/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$/g,
"CSS/ELEMENT TEST"
);
}
});
}}
};
Problem: The window.onload
works fine at loading screen which is <h1>Loading...</h1>
here. I could see the console logs when I try to. But after location.replace
all the manipulates would be gone. As barely actually.
MyQuestion: So how can I manipulate elements and css after localization ?
What I've tried ?: I tried to implement webview with svelte to tauri app but I couldn't get a healthy result.
<script>
let url="https://web.whatsapp.com"
console.log("euheuheueheu")
</script>
<h1>
asfafsaf
</h1>
<webview
src={url}
preload="script.js"
>
</webview>
I also tried:
fn main() {
let webview = tauri::Builder::default()
// ... other Tauri configuration options
.invoke_handler(tauri::generate_handler![...])
.run(tauri::generate_context!())
.expect("failed to run app");
webview
.current_window()
.expect("failed to get current window")
.spawn(
tauri::WebviewBuilder::new()
// ... other webview configuration options
.initialization_script(include_str!("preload.js")) // load the contents of preload.js
.build()
.expect("failed to build webview"),
)
.expect("failed to spawn webview");
}
But result was same.
Any help appricated. Thankss.
On Electron working one:
<script lang="ts">
window.addEventListener('load', function() { console.log("Fiered load after " + performance.now() + " ms"); }, false);
</script>
<webview
id={`webview-${tab.id}`}
src="https://web.whatsapp.com"
preload="../src/preload.js"
{partition}
bind:this={webviewElement}
useragent={userAgent}
webpreferences={`spellcheck=${tab.config.spellChecker ? 1 : 0}`}
/>