I have been working on a small project for the past week to automatically open Google Chrome, load 7 tabs with different websites in each, and Chromecast to each one of them (there is a different Chromecast for each website). With the help from @gregster and using Chrome.ahk, I have gotten it to work! However, I run into a security error after the 3rd website gets casted. To my knowledge, it doesn't look like an AHK error, but more of a Google Chrome issue, but I do not know how to fix it. Here is my project and the error message I get. Please let me know if anyone can help. Thank you!
Code: Select all
#NoEnv
#Include ../Chrome.ahk
SetBatchLines, -1
; SetTitleMatchMode, 2
; SendMode Input
; Declaring and initializing URL and Chromecast variables
URL1 := "NameOfURL1"
Chromecast1 := "NameOfCast1"
URL2 := "NameOfURL2"
Chromecast2 := "NameOfCast2"
URL3 := "NameOfURL3"
Chromecast3 := "NameOfCast3"
URL4 := "NameOfURL4"
Chromecast4 := "NameOfCast4"
URL5 := "NameOfURL5"
Chromecast5 := "NameOfCast5"
URL6 := "NameOfURL6"
Chromecast6 := "NameOfCast6"
URL7 := "NameOfURL7"
Chromecast7 := "NameOfCast7"
/*
ProfilePath - Path to the user profile directory to use. Will use the standard if left blank.
URLs - The page or array of pages for Chrome to load when it opens.
Flags - Additional flags for chrome when launching.
ChromePath - Path to chrome.exe, will detect from start menu when left blank.
DebugPort - What port should Chrome's remote debugging server run on.
*/
global ChromeInst := new Chrome(,[URL1, URL2, URL3, URL4, URL5, URL6, URL7],"--start-maximized",,9222)
Sleep, 10000
CastPage(URL1, Chromecast1)
CastPage(URL2, Chromecast2)
CastPage(URL3, Chromecast3)
CastPage(URL4, Chromecast4)
CastPage(URL5, Chromecast5)
CastPage(URL6, Chromecast6)
CastPage(URL7, Chromecast7)
CastPage(URL:="", NameOfCast:="") {
if !(PageInst := ChromeInst.GetPageByUrl(URL))
{
MsgBox, Could not retrieve page!
ChromeInst.Kill()
}
else
{
/*
Waits for the page's readyState to match the DesiredState.
DesiredState - The state to wait for the page's ReadyState to match
Interval - How often it should check whether the state matches
*/
PageInst.WaitForLoad("complete", 100)
TabCast := ChromeInst.GetPageByUrl(URL)
TabCast.Call("Cast.enable")
TabCast.Call("Cast.startTabMirroring", { sinkName: NameOfCast})
}
}
^q::
ExitApp