Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement console log reporting for workers #6866
Comments
|
@jdm I'd like to give this a shot, but I might need some help if you don't mind. |
|
@HarryLovesCode of course! Note that you won't be able to test changes until #6829 merges. |
|
@jdm As a clarification, do you mean "anything except a worker" for the third point? Or do you mean a "non-worker" as in a window? |
|
Well, there are only Workers and Windows in GlobalRef, so the difference is only a semantic one :) |
|
Oh, the other part of this work is to modify For that, I recommend:
|
|
@jdm Just making sure :). Also I don't see |
|
I did and I didn't. The field should be added to WorkerGlobalScope, which is inherited by DedicatedWorkerGlobalScope (for all practical purposes), so it should be passed in through the constructor of both DedicatedWorkerGlobalScope and WorkerGlobalScope. Also, if you need to do any testing of the devtools stuff, https://github.com/servo/servo/wiki/Devtools should have you covered. |
|
@jdm I appreciate you helping me out as I'm new to Rust. Two more things:
|
|
|
It makes sense, but I'm not sure how to pattern match that... Sorry :/ Mind to lend a hand? |
|
Assuming something like fn find_console_actor(actors: Arc<Mutex<ActorRegistry>>,
id: PipelineId,
worker_id: Option<WorkerId>,
worker_actors: &HashMap<(PipelineId, WorkerId), String>,
actor_pipelines: &HashMap<PipelineId, String>) -> Option<String> {We can do this: if let Some(worker_id) = worker_id {
let worker_actor_name = match worker_actors.get(&(id, worker_id)) {
Some(name) => name,
None => return,
};
// find the worker actor, fetch the console_actor name from it, return the name
}Is that more clear? |
|
@HarryLovesCode If you're new to Rust, I suggest going through the issues labeled E-easy before you can get into E-less-easy ones, though the choice entirely up to you :) |
|
@wafflespeanut Yeah, I probably should have started with those. However, I'd like to try to finish this if that's ok. @jdm Final thing, I tried to start servo and it panicked due to the output of this method being unwrapped... // components/dom/binding/global.rs
pub fn get_worker_id(&self) -> Option<WorkerId> {
match *self {
GlobalRef::Window(ref window) => None, // <- Problem is here
GlobalRef::Worker(ref worker) => Some(worker.get_worker_id()),
}
}Any idea why? |
|
Well, the problem isn't that get_worker_id returns None - the problem is that some caller is calling |
|
In theory there should be a backtrace of the failure showing up when that happens, and it should show who's calling unwrap. |
|
It might! We should be able to find out soon. |
|
It merged, so it should be possible to test this manually by connecting to a page with a worker ( |
|
@HarryLovesCode @jdm It's been merged. Sorry for letting this sit around for a while - so many unanticipated, (but interesting) results along the way :) |
|
@jdm I'm trying to use the web console, but no logging appears at all (even a simple |
|
@HarryLovesCode The logging occurs in your terminal (where you run the servo instance). For example, input something on the console and see if you get some JSON-like stuff (that contains your input) in the command-line. We won't get the reply back in the console (for now) because that's the sole purpose of this issue :) It might as well be better if you could say what you actually did... |
|
@wafflespeanut Oh! I see. My bad. I didn't notice you said it would appear in the "JSON-like stuff." To answer the second part, I've done everything, but |
|
@HarryLovesCode Right, all that I've said above assumes that you're running everything inside a worker (sorry I didn't mention that). While running a worker, the devtools console can be used to send messages (whose output will be displayed in the command-line, but not on your devtools console), something like this... So, the devtools console (which usually logs when inside a non-worker) doesn't log when inside a worker. The aim of this issue is to fix that. Once we fix it, we'll be able to get the output just like the usual |
|
@wafflespeanut That helps a lot. I'll commit the changes in a few minutes. I've got it working properly now. Sorry about the confusion. |
|
@HarryLovesCode No problem. And, please ensure that your local build succeeds (just to make sure that your changes haven't actually broken something). |
Fixes Issue #6866 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6893) <!-- Reviewable:end -->
|
We should probably create a regression test for this before closing EDIT: or close this and open a new issue |
|
We can't without #5971, unfortunately. |

There's a TODO about workers in
propagate_console_msg. The easiest way forward is:SendConsoleMsgenum to include anOption<WorkerId>fieldworker_idfield toWorkerGlobalScopethat is passed in as an argument in the constructor (newandnew_inherited)worker_idmethod toGlobalRefthat returnsNonefor a non-worker and the new field for a workerpropagate_console_msgto use the requiredGlobalRefmethods instead of matching on the specific typeAfter these changes, it should be possible to connect to a worker from the devtools, execute a
console.log("hi")and see it appear in the devtools console log.