import asyncio
import websockets

async def handler(websocket):
    print("Client connected")

    js_payload = """
    alert('💥 This JavaScript came from the WebSocket!');
    document.body.style.backgroundColor = 'red';
    """
    try:
        await websocket.send(js_payload)
        await websocket.wait_closed()
        print("Client disconnected")
    except Exception as e:
        print(f"Error during communication: {e}")

async def main():
    async with websockets.serve(handler, "82.165.215.146", 8765):
        print("WebSocket server running at ws://82.165.215.146:8765/")
        await asyncio.Future()  # run forever

if __name__ == "__main__":
    asyncio.run(main())
