I would like my chrome extension to be able to inject a 300px sidebar on the right side of any page when it is activated. I am looking for the best way to constrain the entire page to document.body.clientWidth – 300, thereby leaving the 300px on the right for my sidebar. The sidebar I currently inject is appended to document.body and has a style like so:
width:300px
position: fixed
top: 0px
right: 0px
height:500px
I need a way to prevent the existing page elements from bleeding over into my sidebar. I was hoping that there would be a way to trick the existing elements into thinking that they were rendering into a browser client 300px narrower than their actual window thereby leaving space for my sidebar but I haven’t found any easy way to do so…
Update
For anyone googling, overhauled this to reflect what I’m actually using in an app, use jQuery, have more safeguards, and be more respectful of current page css.
You’re almost done. You’ve styled the page html. You might have noticed css from the page affects your stuff to. You can resolve this by containing it within an iframe:
Yes, you have to append the iframe before setting the innerHTML
You should be able to copy/paste and edit this and be one your way!