How would I remove the effects of an event listener on a nested element via a chrome extension?

I have a chrome extension that works as a video overlay to allow for specific timestamp playback.

The extension is activated via keyboard command, and uses a form to input specific time stamps. The problem is: with video.js video elements, number hotkeys are used as inputs to jump the video to select points.

My overlay uses a form, which also requires number inputs. So instead of numbers being entered into the form, the keydown input is used by the video on the page to skip to pre-determined percentages of the overall video time.

Here’s what I know:

  1. The video player is nested within an iframe (“#player”).
  2. The element has an event listener on keydown coming directly from the video.js library file.
  3. When I remove the event listener via the console, the overlay works exactly as expected.

I have tried a number of things, but believe the fact that the video is nested within the iframe stops the typical methods from working.

  • I have tried adding an event listener for the element on keydown with a function that includes event.stopPropogation() and event.preventDefault(). This, however, completely cancels all keydown events relating to the video, preventing me from opening the overlay as well.
  • If I, on second key command, try removing the event listener I’ve placed, the video is not affected at all and functions as usual: allowing me to open the overlay but preventing me from inputting numbers. As though the first key command does not place my event listener, and only on the second key input does it actually place the event listener.
  • I’ve tried accessing the element within the iframe via my content.js file using the contentDocument and contentWindow methods, but this function occurs within the content.js file of my chrome extension which does not have those set of permissions and inevitably requires CORS methods to function. That is something I would want to avoid, as to not overcomplicate compatibility.
  • I’ve also tried hijacking the focus from the video to my overlay, either on key command or once the extension is loaded, neither of which work.

Here is the main point in which I want to disable the video.js event listener, within the keydown method.

  function handleKeydown(event) {
    const isCtrlKey = OSName === "Mac/iOS" ? event.metaKey : event.ctrlKey;
    const isAltKey = OSName === "Mac/iOS" ? event.ctrlKey : event.altKey;

    if (isCtrlKey && isAltKey) {
      if (
        window.location.href.includes("watch") ||
        window.location.href.includes("open") ||
        window.location.href.includes("redbarradio")
      ) {
        // document.activeElement.blur()
        // console.log(document.activeElement)

        overlayVisibleBool.value = !overlayVisibleBool.value;

        const overlayDiv = document.getElementById("rr_overlay");

        if (!overlayDiv) {
          appendOverlay();
          appendListeners();
          appendTippy();
        }

        if (!spotifyOverlayBackground) {
          spotifyOverlayBackground = true;
        }

        toggleOverlay();
        document.getElementById("timeInput").value = "";

        let cancelIt = (event) => {
          event.preventDefault()
          event.stopPropagation()
        }

        let player = document.getElementById("player")
        console.log(player)
        console.log("overlayBool: ", overlayVisibleBool.value)
        // if (overlayVisibleBool.value) {
        //   player.addEventListener("keydown", cancelIt, true)
        //   console.log("Keydown cancelled.")
        // } 
        // else {
        //   player.removeEventListener("keydown", cancelIt, true)
        //   console.log("Keydown enabled.")
        // }
      }
    }
  }

  document.addEventListener("keydown", handleKeydown);

Given that the blank overlay already works to set the video to the inherent time stamp (00:00), and that removing the exact event listener from the “#player” element clears the number input issue, I can’t help but feel I’m missing something very simple with the existing method I’m using.

This is the example video.js site I am using, and here is the complete code for the current version of the chrome extension. Additionally, here is the current version of the chrome extension in the store. Thank you in advance, and no recommendation is too small.

Edit: I’ve narrowed the specific library feature this is due to. The “hotkeys” library within video.js captures the number inputs when the video element is selected, and overrides all other inputs. This event listener is applied to the first iframe’s document element on the site, which is where the video is located.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật