[英]How to detect browser type with Cloud Functions for Firebase?
Inside a Cloud Function, I would like to serve different pages for mobile and desktop. 在Cloud Function内部,我想为移动设备和台式机提供不同的页面。 I would like to know : 我想知道 :
The goal is to serve different users with different urls. 目的是为不同的用户提供不同的URL。
exports.contentServer = functions.https.onRequest((request, response) => {
//determine here if its mobile or not
You can use the following npm package: 您可以使用以下npm软件包:
https://www.npmjs.com/package/detect-browser https://www.npmjs.com/package/detect-browser
Install it by executing in the terminal: 通过在终端中执行安装:
npm i detect-browser
Then you can do for example: 然后,您可以执行以下操作:
const { detect } = require('detect-browser');
const browser = detect();
// handle the case where we don't detect the browser
if (browser) {
console.log(browser.name);
console.log(browser.version);
console.log(browser.os);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.