Created
October 20, 2023 07:28
-
-
Save edoardocavazza/06bc90dfe4e448ff4329c5474699bd37 to your computer and use it in GitHub Desktop.
Saucelabs Safari 15 and above issues with WS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs'; | |
import { createServer as createHttpServer } from 'http'; | |
import { createServer as createHttpsServer } from 'https'; | |
import { WebSocketServer } from 'ws'; | |
import sl from 'saucelabs'; | |
import { remote } from 'webdriverio'; | |
import ip from 'ip'; | |
const protocol = 'http'; | |
const localIp = ip.address(); | |
const port = 8080; | |
const url = `${protocol}://${localIp}:${port}/`; | |
const handler = (req, res) => { | |
res.writeHead(200, { 'Content-Type': 'text/html' }); | |
res.end(`<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<output></output> | |
<script> | |
const output = document.querySelector('output'); | |
const ws = new WebSocket(\`${protocol === 'http' ? 'ws' : 'wss'}://${localIp}:${port}/\`); | |
ws.onopen = () => { | |
output.innerHTML = 'WS connected'; | |
}; | |
ws.onerror = () => { | |
output.innerHTML = 'WS errored'; | |
}; | |
</script> | |
</body> | |
</html>`); | |
}; | |
const server = protocol === 'http' ? createHttpServer(handler) : createHttpsServer({ | |
key: fs.readFileSync('./key.pem'), | |
cert: fs.readFileSync('./cert.pem'), | |
}, handler); | |
new WebSocketServer({ server }); | |
server.listen(port, '0.0.0.0'); | |
console.log(`Server started at ${url}`) | |
const sauce = new sl.default(); | |
console.log('Starting tunnel...'); | |
const tunnel = await sauce.startSauceConnect({ | |
tunnelIdentifier: '1234', | |
noSslBumpDomains: 'all', | |
}); | |
console.log('Tunnel ready'); | |
console.log('Open browser...'); | |
const browser = await remote({ | |
logLevel: 'error', | |
user: process.env.SAUCE_USERNAME, | |
key: process.env.SAUCE_ACCESS_KEY, | |
capabilities: { | |
browserName: 'Safari', | |
browserVersion: '14', | |
// browserVersion: '15', | |
// browserVersion: '16', | |
'sauce:options': { | |
tunnelIdentifier: '1234', | |
}, | |
}, | |
}); | |
console.log('Browser ready'); | |
console.log(`Navigating to ${url} ...`); | |
await browser.navigateTo(url); | |
await new Promise((resolve) => setTimeout(resolve, 5000)); | |
await browser.deleteSession(); | |
console.log('Closing...'); | |
await tunnel.close(); | |
await server.close(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "test-sl", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"type": "module", | |
"dependencies": { | |
"ip": "^1.1.8", | |
"saucelabs": "^7.4.0", | |
"webdriverio": "^8.19.0", | |
"ws": "^8.14.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment