Since you can't access the DOM in a Web Worker, you can't accurately calculate the bounding box of a text label from within the worker.
Some possible work-arounds:
- Do the bounding box calculations on the main thread, then pass messages to the worker with the results. (You don't have to render anything to the screen: just make a detached SVG element that you don't append to the document.)
- Estimate the lengths, by pre-computing the individual character bounding boxes or estimating the average via em-width. After the worker is finished, do checking and correction in the main thread.