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

SetBypassServiceWorker does not work #429

Open
ImmortalD opened this issue Oct 31, 2023 · 0 comments
Open

SetBypassServiceWorker does not work #429

ImmortalD opened this issue Oct 31, 2023 · 0 comments

Comments

@ImmortalD
Copy link

When I set ServiceWorker to bypass network, it still did not take effect, and the request was still cached through the service worker, without requesting network access.

use std::env;
use std::thread::sleep;

use headless_chrome::Browser;
use headless_chrome::LaunchOptions;
use headless_chrome::protocol::cdp::Network::{*, SetBypassServiceWorker};
use headless_chrome::protocol::cdp::ServiceWorker::{*};
use headless_chrome::protocol::cdp::Target::CreateTarget;

fn main() {
    env::set_var("RUST_LOG", "trace");
    env_logger::init();


    let mut opt = LaunchOptions::default();
    opt.headless = false;
    let browser = Browser::new(opt).unwrap();

    let tab = browser.new_tab_with_options(CreateTarget {
        url: "about:blank".to_string(),
        width: Some(1024),
        height: Some(800),
        browser_context_id: None,
        enable_begin_frame_control: None,
        new_window: None,
        background: None,
    }).unwrap();


    // do not work
    let by_pass_work = SetBypassServiceWorker { bypass: true };
    tab.call_method(by_pass_work).unwrap();

    // let dis_cache = SetCacheDisabled { cache_disabled: true };
    // tab.call_method(dis_cache).unwrap();

    tab.navigate_to("https://live.douyin.com/431061771246").unwrap();
    println!("pid = {:?}", browser.get_process_id());

    sleep(std::time::Duration::from_secs(60 * 10));
}

The logs related to SetBypassServiceWorker are as follows

[2023-10-31T05:27:57Z TRACE headless_chrome::browser::tab] Calling method: SetBypassServiceWorker { bypass: true }
[2023-10-31T05:27:57Z TRACE headless_chrome::browser::transport] Msg to tab: {"method":"Network.setBypassServiceWorker","id":22,"params":{"bypass":true}}
[2023-10-31T05:27:57Z TRACE headless_chrome::browser::transport] waiting for response from call registry: 23 "SendMessageToTarget { message: \"{\\\"method\\\":\\\"Network.setBypassServiceWorker\\\",\\\"id\\\":22,\\\"params\\\":{\\\"bypass\\\":true}}\", session_id: Some(\"9E4EA88D35F262439A120AC0A6FD9B5F\"), target_id: None }"
[2023-10-31T05:27:57Z TRACE headless_chrome::browser::transport] received response for: 23 "SendMessageToTarget { message: \"{\\\"method\\\":\\\"Network.setBypassServiceWorker\\\",\\\"id\\\":22,\\\"params\\\":{\\\"bypass\\\":true}}\", session_id: Some(\"9E4EA88D35F262439A120AC0A6FD9B5F\"), target_id: None }"
[2023-10-31T05:27:57Z TRACE headless_chrome::browser::transport] waiting for response from call registry: 22 "SetBypassServiceWorker { bypass: true }"
[2023-10-31T05:27:57Z TRACE headless_chrome::browser::transport] received response for: 22 "SetBypassServiceWorker { bypass: true }"

The browser request log is as follows, with many of the size columns still being ServiceWork

222
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

1 participant