1
0

More than 1 year has passed since last update.

Error: net::ERR_CONNECTION_REFUSED : #Docker + #Rails 環境で public ディレクトリにあるファイルを headless Chrome で HTML PDF 変換しようとした時のメモ

Last updated at Posted at 2019-11-22

NOTE

  • curl では rails の public な URL に接続できる状態。
  • rails の publiic directory に HTML file を設置して、headless chrome からアクセスしてPDF変換しようとしたとき。( http://localhost:3000/some.html )
  • chrome では localhost が 127.0.0.1 に割り当てられておらず、localhost が使えない場合がありそうだが詳しくは未確認。 http://127.0.0.1:3000/ にアクセスさせると良いかも。
  • 最初 node + puppeter を通して実行させていたが、 どうやら chrome 本体の処理で問題が起きていそうだった。
  • http://127.0.0.1:3000/some.html に接続しても動かず Error: net::ERR_CONNECTION_REFUSED が起こることがあった
  • docker container で hostname -i した結果のIPアドレスに対して chrome をアクセスすると動くケースがあった。 ( http://172.26.0.1:3000/some.html )

コマンド例

chromium-browser --headless --no-sandbox --disable-gpu --print-to-pdf http:/xxx/
google-chrome-stable --headless --no-sandbox --disable-gpu --print-to-pdf http:/xxx/

参考

ヘッドレス Chrome ことはじめ  |  Web  |  Google Developers

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0