TypeError: Assignment to constant variable ,After Changing it to let/var

TypeError: Assignment to constant variable ,After Changing it to let/var

我正在尝试使用 javascript 语言设置 chrome 二进制文件的二进制路径。 不幸的是,我在 javascript 方面的知识有限,我在尝试这样做时遇到错误,尽管我付出了努力,但我无法解决。 所以事不宜迟,我现在将分享我的问题,希望比我更了解 javascript 的人能帮助我 一些背景: 我在 firebase 中触发一个函数可以运行, 在这个函数中,我正在尝试创建一个 selenium webdriver。 为了这样做:

我需要做那些事情:

  1. chrome驱动程序 --> 在 linux 系统上工作(位于函数项目文件夹内)✅

  2. chrome 位于本机上的浏览器二进制文件 ✅ 3.then,我需要创建一个 chrome 选项对象。 一种。添加一个参数,这样它就没有头了。✅ b.用 chrome 二进制文件的路径设置它。❌

  3. 最后,创建一个 chrome 带有选项的驱动程序,我已创建

目前,我处于3.b

阶段

由于我对javascript的了解不足而引起的错误 这是错误: TypeError: 赋值给常量变量。

这里是什么导致了这个错误

这是我的代码:

exports.initializedChromeDriver = functions.https.onRequest((request, response) => {
  
    async function start_chrome_driver() {

        try {
        functions.logger.info('Hello logs!', {structuredData: true});
        console.log("did enter the function")
        
        const google_site = "https://www.gooogle.com"; 
        const { WebDriver } =  require('selenium-webdriver');
        const {Builder, By} = require('selenium-webdriver');
        
        console.log("will try to initialzed chrome");
        let chrome = require('selenium-webdriver/chrome');
        console.log("did initialzed chrome");
        var chrome_options = new chrome.Options()
        console.log("will try to set the chrome binary Path");
        functions.logger.info('new chrome.Options()', {structuredData: true});
        chrome_options = chrome_options.setChromeBinaryPath(path="/usr/bin/google-chrome");// <------- THIS IS  THE LINE THAT RISE THE ERROR!
        console.log("did setChromeBinaryPath");
        chrome_options.addArguments("--headless");
        let buillder = new Builder().forBrowser('chrome');
        functions.logger.info(' did new Builder().forBrowser(chrome)', {structuredData: true});

        const google_site = 'https://wwww.google.com'
        await driver.get(google_site);
        functions.logger.info('driver did open google site', {structuredData: true});
        
        return  "succ loading google"

        }
        catch (err) {
            console.log('did catch')
            console.error(err);
            return "error loading google";
        }
     

     }
        const p = start_chrome_driver().then((value,reject) => {
            const dic = {};
            dic['status'] = 200;
            dic['data'] = {"message": value};
            response.send(dic);
        });

这是 firebase 函数日志中此代码之后的错误:

我试图将chrome_options对象更改为var/let,并在网上寻找答案,但是在一次又一次地部署之后..我觉得是时候得到了换个角度,任何帮助都可以。

你在这里有一个不必要的分配(路径=...)

chrome_options = chrome_options.setChromeBinaryPath(path="/usr/bin/google-chrome");

只需删除对 path

的分配
chrome_options = chrome_options.setChromeBinaryPath("/usr/bin/google-chrome");