Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 检查网站是否与木偶师一起使用JS功能_Javascript_Google Chrome_Google Chrome Devtools_Puppeteer - Fatal编程技术网

Javascript 检查网站是否与木偶师一起使用JS功能

Javascript 检查网站是否与木偶师一起使用JS功能,javascript,google-chrome,google-chrome-devtools,puppeteer,Javascript,Google Chrome,Google Chrome Devtools,Puppeteer,我的问题与此类似,但不是运行函数,而是通过运行 'use strict'; const puppeteer = require('puppeteer'); (async function main() { try { const browser = await puppeteer.launch(); const [page] = await browser.pages(); await page.goto('https://vsemozhetbyt.githu

我的问题与此类似,但不是运行函数,而是通过运行


'use strict';

const puppeteer = require('puppeteer');

(async function main() {
  try {
    const browser = await puppeteer.launch();
    const [page] = await browser.pages();

    await page.goto('https://vsemozhetbyt.github.io/test/test.html');

    console.log(await page.evaluate(() => test()));

    await browser.close();
  } catch (err) {
    console.error(err);
  }
})();
当前此语句运行test()函数(如果它位于网站中)

   console.log(await page.evaluate(() => test()));

如何修改此语句以检查test()函数是否在网站中基本上我想返回一个布尔值,而不是直接运行该函数。

您只需对函数名执行简单的
typeof
检查,看看它是否存在

typeof existingFunction
将返回“函数”,而
typeof randomName
将返回“未定义”

因此,根据是否有名为
test
的函数,下面应该打印true/false

console.log(wait page.evaluate(()=>typeof test==='function');

console.log(等待页面评估(()=>typeof test=='function'))??如果函数名为test,则返回true;如果函数名为test,则返回false。感谢您的回答,但是如果函数是在JavaScript中定义的,则返回true。我想知道我运行的tru objective网站是否具有测试功能。根据您的问题
当前此语句运行test()函数,如果它在网站中?
,我了解
test()
函数在您运行木偶师的网站中。对吗?如果没有,那么我建议您重新编写您的问题以使其更清楚。再次感谢您的回答,是的,但我也想将此语句用于正常的JS函数,例如,当我运行
console.log(wait page.evaluate(()=>typeof opendirectorypecker=='function')我想得到返回,如果网站有能力显示目录选择器。