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

Update headless chrome #2

Merged
merged 4 commits into from
Mar 10, 2023
Merged

Conversation

konifar
Copy link
Contributor

@konifar konifar commented Mar 9, 2023

Thanks for awesome cli! This will reduce my boring job! 😉

やったこと

rust-headless-chrome のバージョンを v0.9.0 から v1.0.5 に上げました。

経緯

masterブランチでjobcan statusをした際、次のエラーが出ていました。

at 01:48:46 ❯ jobcan status                                                
🌗  Waiting...thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Timeout

   0: backtrace::capture::Backtrace::new_unresolved
   1: failure::backtrace::internal::InternalBacktrace::new
   2: <failure::backtrace::Backtrace as core::default::Default>::default
   3: headless_chrome::browser::Browser::create_browser
   4: headless_chrome::browser::Browser::new
   5: headless_chrome::browser::Browser::default
   6: jobcan::actions::status_action
   7: seahorse::command::Command::run
   8: seahorse::app::App::run
   9: jobcan::main
  10: std::sys_common::backtrace::__rust_begin_short_backtrace
  11: std::rt::lang_start::{{closure}}
  12: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:606:13
      std::panicking::try::do_call
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:483:40
      std::panicking::try
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:447:19
      std::panic::catch_unwind
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panic.rs:137:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/rt.rs:148:48
      std::panicking::try::do_call
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:483:40
      std::panicking::try
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:447:19
      std::panic::catch_unwind
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panic.rs:137:14
      std::rt::lang_start_internal
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/rt.rs:148:20
  13: _main
', /Users/yusuke.konishi/.cargo/git/checkouts/rust-headless-chrome-b5127362e41d64dd/812f10a/src/browser/mod.rs:105:38
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
   2: core::result::unwrap_failed
             at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1791:5
   3: headless_chrome::browser::Browser::default
   4: jobcan::actions::status_action
   5: seahorse::command::Command::run
   6: seahorse::app::App::run
   7: jobcan::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

確認した環境は以下です。

  • Monterey 12.6.2 (21G320)
  • Chromeバージョン: 111.0.5563.64(Official Build) (x86_64)
    • デフォルトブラウザに設定

最小構成のコードで確認してみても Browser::default() で同じエラーが発生していました。
試しに rust-headless-chrome を最新バージョンにしてみたところ成功したのでアップデートしました。
GitHub Releasesを見てみたんですが、どの修正によって解決したのかはまだわかっていません 🙇

確認したこと

  • jobcan status でステータスが表示される
  • jobcan で打刻される

jobcan-cli — -zsh — 200×50 2023-03-10 02-20-07

@@ -6,7 +6,7 @@ edition = "2018"
description = "ジョブカン CLI"

[dependencies]
headless_chrome = { git = "https://github.com/ksk001100/rust-headless-chrome", branch = "feature/add-wait-for-url" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2020年3月時点なので v0.9.0 をベースにしていたようでした

@@ -9,7 +9,7 @@ pub fn punch_in_action(c: &Context) {
let sp = Spinner::new(Spinners::Moon, color::green("Waiting..."));
let jobcan = Jobcan::new(email(c), password(c));
let browser = Browser::default().unwrap();
let tab = browser.wait_for_initial_tab().unwrap();
let tab = browser.new_tab().unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このPRでdeprecatedになりました
rust-headless-chrome/rust-headless-chrome#368

@@ -6,8 +6,7 @@ edition = "2018"
description = "ジョブカン CLI"

[dependencies]
headless_chrome = { git = "https://github.com/ksk001100/rust-headless-chrome", branch = "feature/add-wait-for-url" }
failure = "0.1.7"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::error::Error を使うようになったので不要になりました

@@ -29,14 +30,15 @@ impl Jobcan {
tab.wait_for_element_with_custom_timeout("input.form__login", Duration::from_secs(60))?
.click()?;

tab.wait_for_url("https://ssl.jobcan.jp/employee")?;
// in https://ssl.jobcan.jp/employee
tab.wait_for_element_with_custom_timeout("h3#working_status", Duration::from_secs(20))?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このやり方で一応自分の環境では動作していました
自分が想定できていないケースで動作しないこともありそうなので何かあれば指摘ください 🙏

@ksk001100
Copy link
Owner

@konifar ありがとうございます!マージします!

@ksk001100 ksk001100 merged commit 792ab18 into ksk001100:master Mar 10, 2023
@konifar konifar deleted the update_headless_chrome branch March 10, 2023 03:44
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

Successfully merging this pull request may close these issues.

2 participants