ElyMark: the print page runs none of the document's scripts (M-15)
WebView::open_inert makes a browser with JavaScript off; ElyMark's staged print page uses it. webprobe opens one page both ways: the scripted copy must report, the inert one never. The CEF router drops a query that lacks onFailure, and queries made before the router is ready are lost; agents.md says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6247771f24
commit
d9056c3564
11 files changed
+66
-7
No files matched your search
@@ -220,8 +220,30 @@ impl Probe {
|
||||
self.others.push(view);
|
||||
}
|
||||
|
||||
/// A page named like a URL, and one gone.
|
||||
/// A page named like a URL, one gone, one inert.
|
||||
fn edges(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let page = self.fixtures.join("inert.html");
|
||||
let inert = WebView::open_inert(&page, &self.fixtures, window, cx).expect("a view");
|
||||
cx.subscribe_in(&inert, window, |_, _, event, _, _| match event {
|
||||
Event::Loaded => println!("probe: inert loaded"),
|
||||
Event::Query(_, reply) => {
|
||||
println!("probe: inert ran");
|
||||
reply.ok("");
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.detach();
|
||||
// The same page with scripts: it must run.
|
||||
let scripted = WebView::open(&page, &self.fixtures, window, cx).expect("a view");
|
||||
cx.subscribe_in(&scripted, window, |_, _, event, window, cx| {
|
||||
if let Event::Query(_, reply) = event {
|
||||
println!("probe: scripted ran");
|
||||
reply.ok("");
|
||||
later(cx.weak_entity(), 2000, window, cx, |_, _, _| println!("probe: inert checked"));
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
self.others.extend([inert, scripted]);
|
||||
let hash = self.work.join("hash");
|
||||
std::fs::create_dir_all(&hash).expect("makes");
|
||||
std::fs::copy(
|
||||
|
||||
@@ -197,8 +197,13 @@ fn make_browsers() {
|
||||
runtime_style: RuntimeStyle::ALLOY,
|
||||
..Default::default()
|
||||
};
|
||||
let scripts = match surface.lock().expect("the surface lock").scripts {
|
||||
true => State::ENABLED,
|
||||
false => State::DISABLED,
|
||||
};
|
||||
let settings = BrowserSettings {
|
||||
windowless_frame_rate: 60,
|
||||
javascript: scripts,
|
||||
..Default::default()
|
||||
};
|
||||
// Made at once: no view ever waits on a browser.
|
||||
|
||||
@@ -30,6 +30,8 @@ pub(crate) struct Surface {
|
||||
pub browser: Option<Browser>,
|
||||
/// The view went before its browser came.
|
||||
pub closed: bool,
|
||||
/// Whether the page's scripts run.
|
||||
pub scripts: bool,
|
||||
/// The only folder pages load from, real path.
|
||||
root: PathBuf,
|
||||
/// A folder images alone may also come from.
|
||||
@@ -52,6 +54,7 @@ impl Surface {
|
||||
failed: None,
|
||||
browser: None,
|
||||
closed: false,
|
||||
scripts: true,
|
||||
root,
|
||||
images: None,
|
||||
}
|
||||
|
||||
@@ -86,9 +86,19 @@ impl WebView {
|
||||
}
|
||||
|
||||
/// Opens `page`, a file in `root`, in a new browser.
|
||||
pub fn open(
|
||||
pub fn open(page: &Path, root: &Path, window: &mut Window, cx: &mut App) -> Result<Entity<Self>> {
|
||||
Self::opened(page, root, true, window, cx)
|
||||
}
|
||||
|
||||
/// Opens `page` with its scripts off: shown, never run.
|
||||
pub fn open_inert(page: &Path, root: &Path, window: &mut Window, cx: &mut App) -> Result<Entity<Self>> {
|
||||
Self::opened(page, root, false, window, cx)
|
||||
}
|
||||
|
||||
fn opened(
|
||||
page: &Path,
|
||||
root: &Path,
|
||||
scripts: bool,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Result<Entity<Self>> {
|
||||
@@ -97,7 +107,9 @@ impl WebView {
|
||||
}
|
||||
let root = std::fs::canonicalize(root)?;
|
||||
let page = std::fs::canonicalize(page)?;
|
||||
let surface = Arc::new(Mutex::new(Surface::new(root, window.scale_factor())));
|
||||
let mut surface = Surface::new(root, window.scale_factor());
|
||||
surface.scripts = scripts;
|
||||
let surface = Arc::new(Mutex::new(surface));
|
||||
let url = file_url(&page);
|
||||
if !surface.lock().expect("the surface lock").navigable(&url) {
|
||||
bail!("{} is outside its content folder", page.display());
|
||||
|
||||
Reference in new issue
Block a user