question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resizing the live view iframe

See original GitHub issue

Hello,

I am working on a feature that resizes the iframe in the live viewer. This allows me to record events in a 34" screen and have the whole think viewable on a 23" screen.

It works good for the most part, but the mouse pointer is off. More details below.

Here is how I go about it:

  1. get the size of the wrapper:
rect = document.getElementById('stage_wrapper').getBoundingClientRect();
  1. set the size of the iframe (This is the rrweb player iframe)
$("#stage_wrapper iframe").attr('width',rect.width).attr('height',rect.height);
  1. Then I loop over the live view event positions sent via socketio running them through 2 functions to get the new coordinates. I found these functions on a stack overflow post.

function getNewX(xValue, oldWidth, newWidth){
  return xValue * newWidth / oldWidth;
}

function getNewY(yValue, oldHeight, newHeight){
  return yValue * newHeight / oldHeight;
}

for(var i = 0; i < positions.length; i++) {
    event.data.positions[i].x = getNewX(positions[i].x,e.rect.width, rect.width);
    event.data.positions[i].y = getNewY(positions[i].y,e.rect.height, rect.height);
}

This kind of works. The closer I am to the center of the screen on the recording screen the closer the mouse is to the proper point on the live view screen. The farther away I get from the center of the screen the less accurate the point is correct.

I did find that If I - 75 from the x coordinate like this,

event.data.positions[i].x = getNewX(positions[i].x-75,e.rect.width, rect.width);

the results are pretty close to accurate towards the center but get less accurate as I move closer to the edge just like before.

It is good enough for a demo but not so much long term.

I feel like I am so close to getting this to work but cannot seem to put a finger on the issue.

Do you have any advice, or functions or what I can possibly read about to get closer to my goal?

Thank You,

Randy

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
eoghanmurraycommented, Jul 17, 2020

I think the idea would be along the lines of the following?

<div class="replayer-wrapper" style="transform:scale(0.4);">

Where the 0.4 might be calculated based on knowledge of the browser viewport dimensions vs. size of the recording viewport.

I’ve also got a solution based on a wrapping <svg> and <foreignObject> which makes the replaying full sized and responsive, i.e. if you change the browser viewport dimensions the playback dimensions also scale accordingly so as to always fit on screen.

0reactions
js199069commented, Oct 31, 2022

as we face this problem we find new way to handle it for responsive

          let rr_player = Array.from(document.getElementsByClassName('rr-player') as HTMLCollectionOf<HTMLElement>)
          let player__frame = Array.from(document.getElementsByClassName('rr-player__frame') as HTMLCollectionOf<HTMLElement>)
          player__frame[0].style.width = "100%"
          rr_player[0].style.width = "100%"
      this is for react
      if you want to use it in pure java script  you can use this:
     ` document.getElementsByClassName('rr-player').style.width = "100%"`
      as we set  .style.width = "100%"  we can handle width change with  bootstrap col-
Read more comments on GitHub >

github_iconTop Results From Across the Web

Live View Iframe Sizing - CodePen Blog
On CodePen's Live View, we use a parent <iframe> to listen for updates to the Pen and then inject them or refresh the...
Read more >
How do I resize an iframe? - Splash Help Center
First, locate the iframe element's embed code. · Next, manually resize the iframe element. · What if I'm not sure what size iframe...
Read more >
Using Message Events to Resize an IFrame - This Dot Labs
Click here to see it in action. Dynamically Resizing IFrame. First, a script in the child window checks the height of itself, and...
Read more >
Resize an iframe based on the content - GeeksforGeeks
Contents which needs resizing is done indirectly using a div tag. The trick is to initiate with a div tag and enclose within...
Read more >
How can I make an iframe resizable? - Stack Overflow
The best solution I've found is to set the width and height of the iframe to 100% and put ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found