Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Send info about device back to origin
addEventListener('fetch', event => {
function isMobile(userAgent) {
return userAgent.match(/iPhone|Android|webOS/i) ? 'Yes' : 'No';
async function fetchAndApply(request) {
let isMobileResult = isMobile(request.headers.get('user-agent'))
request = new Request(request)
request.headers.set("Is-Mobile", isMobileResult)
return fetch(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment