Search code examples
javascripthtmlcanvasgoogle-swiffy

Arbitrary Google Swiffy Canvas Size / Off Screen Rendering


I'm using Swiffy to render onto a hidden canvas so that I can take the result and use it elsewhere. The problem I'm running into is that when I resize the container div for Swiffy it won't make the actual canvas any bigger than the available viewport size. If I set the dimensions of the Swiffy div larger than the viewport then the canvas will only get as big as the viewport - it doesn't want to put any part of the canvas offscreen.

I'm sure this is for efficiency, there's no reason to render something if it's offscreen normally, but I need to have Swiffy render it all the time, at whatever size I want.

Additionally, Swiffy just plain refuses to do anything if the Swiffy container div isn't attached to the DOM. (Forces the canvas to have a width and height of 0).

Is there a way around this without having to dig into the (obfuscated) Swiffy client runtime and modify it? How can I trick Swiffy into rendering larger than the viewport size?

Edit: I was actually able to trick swiffy into rendering larger than the viewport by changing window.innerWidth to whatever I want. That's a really ugly hack though and I hate to overwrite that as it causes a lot of issues.


Solution

  • If your swiffy runtime version is 7.3, you can hack the js directly.

    Just remove or comment "b.xj(c);" in g.Tp() function. I don't care any advantage of offscreen rendering. At least, it works now.

    I think it's a serious bug.

    Note that it's good in iframe, no need to hack.