作为测试,我尝试用 jquery 替换tonejs,并且评估中存在对“$”的引用,但是当我尝试加载tonejs 时,对“Tone”的引用不存在。有任何想法吗?
import asyncio
from pyppeteer import launch
async def main():
browser = await launch({
"headless": True,
"ignoreDefaultArgs": [
"--mute-audio",
],
"args": [
"--autoplay-policy=no-user-gesture-required",
"--no-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu",
"--no-zygote",
'--disable-setuid-sandbox',
'--single-process'
]
})
page = await browser.newPage()
await page.addScriptTag({
"url": "https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.26/Tone.min.js"
# "url": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
})
res = await page.evaluate('''() => {
return {
"r": Tone.toString()
// THIS WORKS WHEN JQUERY IS LOADED ABOVE
// "r": $.toString()
}
}''')
await browser.close()
return res
def handler(context, event):
return asyncio.run(main())
编辑:适用于 ToneJS 版本14.5.37,但不是最新(14.8.26)版本。