30 lines
780 B
JavaScript
30 lines
780 B
JavaScript
// src-tauri/inject.js
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
console.log('Initializing local background socket link...')
|
|
const ws = new WebSocket('ws://127.0.0.1:8080')
|
|
|
|
ws.onopen = () => {
|
|
console.log('WebSocket connected successfully!')
|
|
const payload = {
|
|
command: 'remote_action',
|
|
message: 'Hello automatically from: ' + window.location.href
|
|
}
|
|
ws.send(JSON.stringify(payload))
|
|
}
|
|
|
|
ws.onmessage = event => {
|
|
console.log('📩 RECEIVED REPLY FROM TAURI BACKEND:', JSON.parse(event.data))
|
|
ws.send(
|
|
JSON.stringify({
|
|
localsession: window.localStorage.getItem('token') || 'no-session'
|
|
})
|
|
)
|
|
}
|
|
|
|
ws.onerror = err => {
|
|
console.error('Connection failed:', err)
|
|
}
|
|
|
|
window.localAppSocket = ws
|
|
})
|