zhw2590582 / ArtPlayer

:art: ArtPlayer.js is a modern and full featured HTML5 video player
https://artplayer.org
MIT License
2.55k stars 269 forks source link

Script Not executing on OnSelect function #781

Closed dev-AshishRanjan closed 3 months ago

dev-AshishRanjan commented 3 months ago

Expected behaviour

It should open a new tab in browser and and go to the specified url

Actual behaviour

No Redirection is found

Steps to reproduce

Code :

settings: [
        {
          html: "Subtitle",
          width: 250,
          tooltip: "",
          selector: subtitles,
          onSelect: function (item, $dom, event) {
            console.info(item, $dom, event);
            art.subtitle.url = item?.url;
            return item?.html;
          },
        },
        {
          html: "Watch Party",
          width: 250,
          height: 500,
          selector: [
            {
              html: "watchparty.me",
              url: "https://www.watchparty.me/create?video=" + option?.url,
            }
          ],
          onSelect: function (item: any) {
            setTimeout(() => {
              window.open(option?.url);
            }, 0);
          },
        },
        {
          html: "Download",
          width: 250,
          height: 500,
          icon: '<img src="/images/logo512.svg" alt="download"/>',
          selector:
            format === "hls"
              ? [
                {
                  html: "Download HLS (Recommended)",
                  url: option.url,
                  opt: 1,
                },
                {
                  html: "Download HLS (mediatools)",
                  url: option.url,
                  opt: 2,
                },
                {
                  html: "Download HLS (thetuhin)",
                  url: option.url,
                  opt: 3,
                },
              ]
              : [
                {
                  html: "Download mp4",
                  url: option.url,
                  opt: 4,
                },
              ],
          onSelect: function (item: any) {
            if (item.opt === 1)
              window.open(
                `https://hlsdownload.vidbinge.com/?url=${option.url}`,
              );
            if (item.opt === 2)
              window.open(
                `https://mediatools.cc/hlsDownloader?query=${option.url}`,
              );
            if (item.opt === 3) {
              navigator?.clipboard?.writeText(option.url);
              window.open(
                `https://hlsdownloader.thetuhin.com/?text=${option.url}`,
              );
            }
            if (item.opt === 4) {
              navigator?.clipboard?.writeText(option.url);
              window.open(`${option.url}`);
            }
          },
        },
      ],

Few days back, after selecting the submenu, it use to run the script

 window.open(
       `https://hlsdownload.vidbinge.com/?url=${option.url}`,
    );

but now this script is not running in onSelect function

Environment

Console errors (if any)

no error

Link to where the bug is happening

https://rivestream.live/watch?type=movie&id=786892

zhw2590582 commented 3 months ago

I can execute this code in your demo link

window.open( https://hlsdownload.vidbinge.com/?url=${option.url}, );

dev-AshishRanjan commented 3 months ago

@zhw2590582 ,

I have changed the logic. window.open() is still not working

The new logic to do this is:

onSelect: function (item: any) {
            // window.open("https://www.watchparty.me/create?video=" + option?.url);
            // window.location.href = "https://www.watchparty.me/create?video=" + option?.url;
            let url = `https://www.watchparty.me/create?video=${option.url}`;
            let event = new MouseEvent("click", {
              bubbles: true,
              cancelable: true,
              view: window,
            });
            let a = document.createElement("a");
            a.href = url;
            a.target = "_blank";
            a.dispatchEvent(event);
          },
dev-AshishRanjan commented 3 months ago

The issue has been resolved from my side by changing logic. But I would like to mention that window.open() was working few days back.

Thanks for your support, I am closing this issue 👍

zhw2590582 commented 3 months ago

Maybe you accidentally modified the Chrome security policy, you may have disabled the use of JS to open third-party pages, you can try using incognito mode