Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download timeout error #2

Open
williamyang2008 opened this issue Jul 9, 2023 · 10 comments
Open

Download timeout error #2

williamyang2008 opened this issue Jul 9, 2023 · 10 comments

Comments

@williamyang2008
Copy link

和之前有位同学反应的情况类似,也是出现download timeout的错误,提示如下:

Error: Download timed out
at Timeout._onTimeout (file:///C:/Users/Administrator/main.js:256:16)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)

@williamyang2008
Copy link
Author

image
timeout超时时长调整为60秒依然会提示超时错误

@renyunkang
Copy link
Owner

这里的原理是:使用一个 watcher 来监测本地文件的变化,如果监测的对应文件被创建并且成功写入后表示下载完成,超时表示文件没有写入完成,所以先从下面两个方面看下有没有问题:

  1. 相应文件名称有没有被创建
  2. 下载的 url 是否有效,可能是用户自定义的一些操作导致 url 失效或者被修改

@williamyang2008
Copy link
Author

这里的原理是:使用一个 watcher 来监测本地文件的变化,如果监测的对应文件被创建并且成功写入后表示下载完成,超时表示文件没有写入完成,所以先从下面两个方面看下有没有问题:

  1. 相应文件名称有没有被创建
  2. 下载的 url 是否有效,可能是用户自定义的一些操作导致 url 失效或者被修改

1,检查了下载的目标地址,没有文件夹及文件被创建
2,我看了下代码,不知道docUrl是怎么定义(拼接的),但我按照代码中的提示,将某知识库的地址+slug信息+'/markdown?attachment=true&latexcode=false&anchor=false&linebreak=false'; 是可以成功下载markdown文件的。所以在想是不是因为docUrl的缘故所以导致下载链接失效?望指点。谢谢!
Snipaste_2023-07-10_11-59-20

@renyunkang
Copy link
Owner

你可以打印看看 docurl 是否正确,是否可以直接在浏览器中下载

你可以修改 https://github.com/renyunkang/yuque-exporter/blob/master/main.js#L41C1-L41C87headless: false 会在运行时显示浏览器的运行状态,方便你去调试

@williamyang2008
Copy link
Author

你可以打印看看 docurl 是否正确,是否可以直接在浏览器中下载

你可以修改 https://github.com/renyunkang/yuque-exporter/blob/master/main.js#L41C1-L41C87headless: false 会在运行时显示浏览器的运行状态,方便你去调试

感谢,按照建议,观察了下浏览器的运行状态。解析知识库及文档都很正常,就是进入到下载环节,就开始报错了。
Snipaste_2023-07-10_22-42-30

chrome只提供了一个帮助文档的链接:https://support.google.com/chrome/answer/2898334?hl=zh-Hans&ctx=1&visit_id=638245973802105273-1324968125&p=ui_download_errors&rd=1

请教下如何能进一步定位下载遇到的具体问题呢?谢谢!

@renyunkang
Copy link
Owner

没遇到过这个问题,你看看是不是权限的问题,用 admin 运行 cmd 或者 powershell 试试

@ideapad460
Copy link

ideapad460 commented Jul 13, 2023

直接运行会超时,{ headless: false }看了下发现会404,把ACCESSURL去掉域名 https://www.yuque.com/ 就可以成功下载了

@318197375
Copy link

按照@ideapad460的办法修改过, ACCESSURL已经将域名去掉了, 但还是在下载这步时出现一样的问题. 但是如果将在cmd打印出来的URL复制到edge中, 是可以下载的. 已排除文件夹操作权限的问题.
image

@renyunkang
Copy link
Owner

我自己测试没有问题,排除官方增加限制的一小部分可能(也不能完全排除),也有可能是用户自定义信息不同导致拼装的 url 不一致。

从下面几个方面再试试吧:

  • 可以换用本机 edge 浏览器路径尝试,修改方式见下图
  • 在程序运行时,打开headless: false,在下载出错时,手动操作导出文章看下有什么反应,对比 url 和实际文档的 url 是否一致

image

@daonatural
Copy link

windows10, node v16.18.0 相同的问题,浏览器下载时控制台报错:The service worker navigation preload request was cancelled before 'preloadResponse' settled. If you intend to use 'preloadResponse', use waitUntil() or respondWith() to wait for the promise to settle.
我通过下面方式解决问题:
下载文件处代码替换成如下方式

import { win32 } from "node:path";
...
...
const client = await page.target().createCDPSession();
const options = { output: folderPath };
await client.send("Browser.setDownloadBehavior", {
  behavior: "allow",
  downloadPath: win32.resolve(win32.normalize(options.output)),
  // folderPath,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants