chrome_wasm_bindgen/
devtools.rs1use serde::{Deserialize, Serialize};
2use wasm_bindgen::prelude::*;
3
4#[wasm_bindgen]
5extern "C" {
6 #[wasm_bindgen(extends = js_sys::Object)]
7 pub type Devtools;
8
9 #[wasm_bindgen(method, getter, js_name = inspectedWindow)]
10 pub fn inspected_window(this: &Devtools) -> InspectedWindow;
11}
12
13#[wasm_bindgen]
14extern "C" {
15 #[wasm_bindgen(extends = js_sys::Object)]
16 #[doc = "Use the chrome.devtools.inspectedWindow API to interact with the inspected window: obtain the tab ID for the inspected page, evaluate the code in the context of the inspected window, reload the page, or obtain the list of resources within the page."]
17 #[doc = ""]
18 #[doc = "Availability: Since Chrome 18."]
19 pub type InspectedWindow;
20
21 #[wasm_bindgen(method, getter, js_name = tabId)]
22 #[doc = "The ID of the tab being inspected. This ID may be used with chrome.tabs.* API."]
23 pub fn tab_id(this: &InspectedWindow) -> u32;
24
25 #[wasm_bindgen(method)]
26 #[doc = "Reloads the inspected page."]
27 pub fn reload(this: &InspectedWindow);
28
29 #[wasm_bindgen(method, js_name = reload)]
30 #[doc = "Reloads the inspected page."]
31 pub fn reload_with_options(this: &InspectedWindow, options: JsValue);
32
33 #[wasm_bindgen(method, js_name = eval)]
34 #[doc = "Evaluates a JavaScript expression in the context of the main frame of the inspected page. The expression must evaluate to a JSON-compliant object, otherwise an exception is thrown. The eval function can report either a DevTools-side error or a JavaScript exception that occurs during evaluation. In either case, the result parameter of the callback is undefined. In the case of a DevTools-side error, the isException parameter is non-null and has isError set to true and code set to an error code. In the case of a JavaScript error, isException is set to true and value is set to the string value of thrown object."]
35 #[doc = ""]
36 #[doc = "@param expression An expression to evaluate."]
37 pub fn eval_with_expression(this: &InspectedWindow, expression: &str);
38
39 #[wasm_bindgen(method, js_name = eval)]
40 #[doc = "Evaluates a JavaScript expression in the context of the main frame of the inspected page. The expression must evaluate to a JSON-compliant object, otherwise an exception is thrown. The eval function can report either a DevTools-side error or a JavaScript exception that occurs during evaluation. In either case, the result parameter of the callback is undefined. In the case of a DevTools-side error, the isException parameter is non-null and has isError set to true and code set to an error code. In the case of a JavaScript error, isException is set to true and value is set to the string value of thrown object."]
41 #[doc = ""]
42 #[doc = "@param expression An expression to evaluate."]
43 #[doc = ""]
44 #[doc = "@param callback A function called when evaluation completes."]
45 #[doc = ""]
46 #[doc = "Parameter result: The result of evaluation."]
47 #[doc = ""]
48 #[doc = "Parameter exceptionInfo: An object providing details if an exception occurred while evaluating the expression."]
49 pub fn eval_with_expression_and_callback(this: &InspectedWindow, callback: js_sys::Function);
50
51 #[wasm_bindgen(method, js_name = eval)]
52 #[doc = "Evaluates a JavaScript expression in the context of the main frame of the inspected page. The expression must evaluate to a JSON-compliant object, otherwise an exception is thrown. The eval function can report either a DevTools-side error or a JavaScript exception that occurs during evaluation. In either case, the result parameter of the callback is undefined. In the case of a DevTools-side error, the isException parameter is non-null and has isError set to true and code set to an error code. In the case of a JavaScript error, isException is set to true and value is set to the string value of thrown object."]
53 #[doc = ""]
54 #[doc = "@param expression An expression to evaluate."]
55 #[doc = ""]
56 #[doc = "@param options The options parameter can contain one or more options."]
57 pub fn eval_with_expression_and_options(this: &InspectedWindow, options: JsValue);
58
59 #[wasm_bindgen(method, js_name = eval)]
60 #[doc = "Evaluates a JavaScript expression in the context of the main frame of the inspected page. The expression must evaluate to a JSON-compliant object, otherwise an exception is thrown. The eval function can report either a DevTools-side error or a JavaScript exception that occurs during evaluation. In either case, the result parameter of the callback is undefined. In the case of a DevTools-side error, the isException parameter is non-null and has isError set to true and code set to an error code. In the case of a JavaScript error, isException is set to true and value is set to the string value of thrown object."]
61 #[doc = ""]
62 #[doc = "@param expression An expression to evaluate."]
63 #[doc = ""]
64 #[doc = "@param options The options parameter can contain one or more options."]
65 #[doc = ""]
66 #[doc = "@param callback A function called when evaluation completes."]
67 #[doc = ""]
68 #[doc = "Parameter result: The result of evaluation."]
69 #[doc = ""]
70 #[doc = "Parameter exceptionInfo: An object providing details if an exception occurred while evaluating the expression."]
71 pub fn eval_with_expression_and_options_and_callback(
72 this: &InspectedWindow,
73 options: JsValue,
74 callback: js_sys::Function,
75 );
76
77 #[wasm_bindgen(method, js_name = getResources)]
78 #[doc = "Retrieves the list of resources from the inspected page."]
79 #[doc = ""]
80 #[doc = "@param callback A function that receives the list of resources when the request completes."]
81 pub fn get_resources(this: &InspectedWindow, callback: js_sys::Function);
82
83 #[wasm_bindgen(method, setter, js_name = onResourceAdded)]
84 #[doc = "Fired when a new resource is added to the inspected page."]
85 pub fn on_resource_added(this: &InspectedWindow, value: js_sys::Function);
86
87 #[wasm_bindgen(method, setter, js_name = onResourceContentCommitted)]
88 #[doc = "Fired when a new revision of the resource is committed (e.g. user saves an edited version of the resource in the Developer Tools)."]
89 pub fn on_resource_content_committed(this: &InspectedWindow, value: js_sys::Function);
90}
91
92#[derive(Serialize, Deserialize)]
93struct ReloadOptions<'a> {
94 #[serde(alias = "userAgent")]
95 user_agent: Option<&'a str>,
97 #[serde(alias = "ignoreCache")]
98 ignore_cache: Option<bool>,
100 #[serde(alias = "injectedScript")]
101 injected_script: Option<&'a str>,
103 #[serde(alias = "preprocessorScript")]
104 preprocessor_script: Option<&'a str>,
110}
111
112impl From<ReloadOptions<'_>> for JsValue {
113 fn from(value: ReloadOptions) -> Self {
114 serde_wasm_bindgen::to_value(&value).unwrap()
115 }
116}
117
118#[derive(Serialize, Deserialize)]
119struct EvalOptions<'a> {
120 #[serde(alias = "frameURL")]
121 frame_url: Option<&'a str>,
123 #[serde(alias = "useContentScriptContext")]
124 use_content_script_context: Option<bool>,
126 #[serde(alias = "contextSecurityOrigin")]
127 context_security_origin: Option<&'a str>,
129}
130
131impl From<EvalOptions<'_>> for JsValue {
132 fn from(value: EvalOptions) -> Self {
133 serde_wasm_bindgen::to_value(&value).unwrap()
134 }
135}