Failed to gather url on browser windows via osascript (Apple Script)

I've been using Apple Script below for gathering every title & url of opening tab from browser window. It's been works fine for a few years but it's failed recently (maybe in last two weeks).

#!/usr/bin/env osascript -l JavaScript

// url.js
function run(arg) {
  arg = arg.toString()
  let browser = ''
  switch(arg) {
    case 'chrome':
      browser = 'Google Chrome'
      break;
    case 'edge':
      browser = "Microsoft Edge"
      break;
    default:
      browser = 'Google Chrome'
      break;
  }

  Application(browser).windows().forEach((window) => {
    console.log('\n\n')
    window.tabs().forEach((tab) => {
      const url  = tab.url()
      const name = tab.name()
      console.log(`${name}\t${url}`)
    })
  })
}

It's been works like below (imagine that you open https://example.com on edge)

$ url.js edge
example.com https://example.com

But I found it failed today.

$ url.js edge
execution error: Error: Error: Application isn't running. (-600)

of course I'm make sure Edge browser up and running. Same error for Chrome. I keep my environments(os, browser etc) up-to-date but I don't know which updates affects here.

Any thoughts or helps are welcome.

Settings

  • MacBook Pro M2
  • Sonoma 14.2.1
  • Edge 122
  • Chrome 122