0

I am trying to open up a new tab using javascript. It doesn't work and I get the error:

[Error] SyntaxError: Unexpected token ':'. Expected ')' to end an argument list.
    (anonymous function)

Here is my code:

function openTab() {
    let myUrl = URL(string: "https://google.com")


    // This grabs the active window.
    SFSafariApplication.getActiveWindow { (activeWindow) in

        // Request a new tab on the active window, with the URL we want.
        activeWindow?.openTab(with: myUrl, makeActiveIfPossible: true, completionHandler: {_ in
        })
    }
}

openTab();

Thanks!

Ajy_Chikn
  • 3
  • 3

1 Answers1

0

A syntax error. You forgot the braces in the object on line two. It should be

URL({ string: "https:your.url" });

Instead of:

URL(string: "https:your.url");
MattC
  • 73
  • 8
  • Thanks! But, now I am getting error: `SyntaxError: Unexpected token '{'` – Ajy_Chikn Dec 02 '21 at 12:13
  • Now I looked in deeper and are you sure the above code is javascript? The section after `SFSafariApplication` doesn't correspond to any JS syntax. Especially with specifying all the parameters in parentheses like `(parameter: value)` it looks like Dart to me. – MattC Dec 02 '21 at 12:22
  • Thanks. I couldn't figure out how to open tabs using safari, so I found the code on someone else's question. Here is the link to where I got the code: [link](https://stackoverflow.com/questions/51358864/open-new-tab-with-javascript-in-safari-12-safari-app-extension). Would using `window.open(url, "_blank");` work? I tried it but it didn't work for me. – Ajy_Chikn Dec 02 '21 at 23:28
  • The code provided is Swift code. window.open failed for me too, with Safari showing that a popup has been blocked. You need to run window.open in response to a real click event. – koral Feb 24 '23 at 20:20