[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Forced to browser-sniff Safari version

Richard Maher

4/1/2015 8:49:00 AM

Can someone tell me the "best" way to detect Safari and then its version
number?

Look, I don't want to do it but I can't find a way to pin down a WORKING
version of speechSynthesis on Safari :-(

See below for an example that works on iOS 7.1.2 *IF* you don't add the
onEnd listener. Apart from that everything is peachy.

In my real world full blown example it talks but still won't deliver the
at end event.

On iOS 8 there is no issue. (I'm assuming here Safari versions are tied
to the OS?)

Please offer a best-of-breed agent sniffer or a better
working-feature-detector.

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function fini()
{
alert("end");
}
function talk()
{
if (!('speechSynthesis' in window)) {
alert("Unsupported browser");
return;
}

alert("Getting ready.");
var utterance = "Hello World";
var chat = new SpeechSynthesisUtterance(utterance);

chat.addEventListener('end', fini, false);

speechSynthesis.speak(chat);

}
</script>
</head>
<body>

<p>On Safari this example won't fire any known events<br />
onend, onerror, even onended: -</p>

<input type="button" value="Talk" onclick="talk()" />
<br /><br />
No probs on Chrome or Opera. Spewin!
</body>
</html>
25 Answers

JJ

4/1/2015 12:20:00 PM

0

Don't rely on User-Agent to determine the browser engine and version.
Detect by browser features and bugs instead.

Richard Maher

4/1/2015 12:36:00 PM

0

On 4/1/2015 8:19 PM, JJ wrote:
> Don't rely on User-Agent to determine the browser engine and version.
> Detect by browser features and bugs instead.
>
On 4/1/2015 8:19 PM, JJ wrote:
> Don't rely on User-Agent to determine the browser engine and version.
> Detect by browser features and bugs instead.
>
Excellent! Please show me (or even just tell me) how you you would
detect Safari's implementation of speechSynthesis not .speak()ing or an
ONEND event listener not firing on a completed SpeechSynthesisUtterance.

Implementation details left as an exercise for the reader?

Just thought you'd trot out some bullshit you read in Javascript Weekly?

To help you out here's my *SSCCE* again as you forgot to quote anything: -

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function fini()
{
alert("end");
}
function talk()
{
if (!('speechSynthesis' in window)) {
alert("Unsupported browser");
return;
}

alert("Getting ready.");
var utterance = "Hello World";
var chat = new SpeechSynthesisUtterance(utterance);

chat.addEventListener('end', fini, false);

speechSynthesis.speak(chat);

}
</script>
</head>
<body>

Denis McMahon

4/1/2015 2:51:00 PM

0

On Wed, 01 Apr 2015 20:35:52 +0800, Richard Maher wrote:

> On 4/1/2015 8:19 PM, JJ wrote:
>> Don't rely on User-Agent to determine the browser engine and version.
>> Detect by browser features and bugs instead.

> On 4/1/2015 8:19 PM, JJ wrote:
> > Don't rely on User-Agent to determine the browser engine and version.
> > Detect by browser features and bugs instead.

> Excellent! Please show me (or even just tell me) how you you would
> detect Safari's implementation of speechSynthesis not .speak()ing or an
> ONEND event listener not firing on a completed SpeechSynthesisUtterance.

Identify a 'feature' whose presence or absence in the browser correlates
to the differences in browser behaviour which you are interested in, and
test for the presence or absence of that feature.

The best place to find out about such features is in the browser
changelogs and / or browser specific forums.

--
Denis McMahon, denismfmcmahon@gmail.com

Scott Sauyet

4/1/2015 4:36:00 PM

0

Denis McMahon wrote:
> Richard Maher wrote:
>> JJ wrote:
>>> Don't rely on User-Agent to determine the browser engine and version.
>>> Detect by browser features and bugs instead.
>
>> Excellent! Please show me (or even just tell me) how you you would
>> detect Safari's implementation of speechSynthesis not .speak()ing or an
>> ONEND event listener not firing on a completed SpeechSynthesisUtterance.
>
> Identify a 'feature' whose presence or absence in the browser correlates
> to the differences in browser behaviour which you are interested in, and
> test for the presence or absence of that feature.
>
> The best place to find out about such features is in the browser
> changelogs and / or browser specific forums.

Or by asking a well-phrased, carefully delineated question that shows
excellent understanding of what should be done before asking a question
as well as a handle on the complexities and subtleties of the subject --
in a forum frequented by people likely to have the relevant expertise
with a charter that clearly includes the topic at hand.

Richard could do that too... Oh wait, it seems he already did.

To the OP: I'm sorry I have no suggestions at all. Of late, I've been
mostly insulated from significant cross-browser issues, and never dealt
with any speech synthesis APIs in any form. But I do believe yours was
a well-asked and well-directed question.


-- Scott

Richard Maher

4/1/2015 10:28:00 PM

0

On 4/1/2015 10:50 PM, Denis McMahon wrote:

> Identify a 'feature' whose presence or absence in the browser correlates
> to the differences in browser behaviour which you are interested in, and
> test for the presence or absence of that feature.
>
> The best place to find out about such features is in the browser
> changelogs and / or browser specific forums.
>

More inane platitudes from self-righteous pompous twat?

Let's acknowledge the elephant in the room - It can't be done dick-head!

Richard Maher

4/1/2015 10:30:00 PM

0

On 4/2/2015 12:35 AM, Scott Sauyet wrote:
> Or by asking a well-phrased, carefully delineated question that shows
> excellent understanding of what should be done before asking a question
> as well as a handle on the complexities and subtleties of the subject --
> in a forum frequented by people likely to have the relevant expertise
> with a charter that clearly includes the topic at hand.
>
> Richard could do that too... Oh wait, it seems he already did.
>
> To the OP: I'm sorry I have no suggestions at all. Of late, I've been
> mostly insulated from significant cross-browser issues, and never dealt
> with any speech synthesis APIs in any form. But I do believe yours was
> a well-asked and well-directed question.
>
Cheers Mate.

Christoph M. Becker

4/1/2015 11:04:00 PM

0

Richard Maher wrote:

> On 4/1/2015 10:50 PM, Denis McMahon wrote:
>
>> Identify a 'feature' whose presence or absence in the browser correlates
>> to the differences in browser behaviour which you are interested in, and
>> test for the presence or absence of that feature.
>>
>> The best place to find out about such features is in the browser
>> changelogs and / or browser specific forums.
>>
>
> More inane platitudes from self-righteous pompous twat?
>
> Let's acknowledge the elephant in the room - It can't be done dick-head!

What Denis suggests might well be doable -- but it would only be
slightly better than browser sniffing, if at all, see [1].

If proper feature detection is not possible, as you already have
suggested, you may consider to ask somewhere else for the "best" browser
sniffing technique. This newsgroup's FAQ, which you most certainly did
read, explicitly mentions that browser sniffing is to be avoided[2] --
so what do you expect?

[1] <http://pointedears.de/scripts/faq/cljs/notes/detect-browser...
[2] <http://pointedears.de/scripts/faq/cljs/#detectB...

--
Christoph M. Becker

Andrew Poulos

4/1/2015 11:54:00 PM

0

On 1/04/2015 11:35 PM, Richard Maher wrote:
> On 4/1/2015 8:19 PM, JJ wrote:
>> Don't rely on User-Agent to determine the browser engine and version.
>> Detect by browser features and bugs instead.
>>
> On 4/1/2015 8:19 PM, JJ wrote:
> > Don't rely on User-Agent to determine the browser engine and version.
> > Detect by browser features and bugs instead.
> >
> Excellent! Please show me (or even just tell me) how you you would
> detect Safari's implementation of speechSynthesis not .speak()ing or an
> ONEND event listener not firing on a completed SpeechSynthesisUtterance.
>
> Implementation details left as an exercise for the reader?
>
> Just thought you'd trot out some bullshit you read in Javascript Weekly?

You realise that if you ever went for a job and the potential employer
googled your name (assuming you are using your real name) then they'd
probably view you, because of your "nasty" replies, with disdain.

Andrew Poulos

Michael Haufe (\"TNO\")

4/2/2015 1:00:00 AM

0

On Wednesday, April 1, 2015 at 3:49:28 AM UTC-5, Richard Maher wrote:
> Can someone tell me the "best" way to detect Safari and then its version
> number?
>
> Look, I don't want to do it but I can't find a way to pin down a WORKING
> version of speechSynthesis on Safari :-(
>
> See below for an example that works on iOS 7.1.2 *IF* you don't add the
> onEnd listener. Apart from that everything is peachy.
>
> In my real world full blown example it talks but still won't deliver the
> at end event.
>
> On iOS 8 there is no issue. (I'm assuming here Safari versions are tied
> to the OS?)
>
> Please offer a best-of-breed agent sniffer or a better
> working-feature-detector.
>
> <!DOCTYPE html>
> <html>
> <head>
> <script type="text/javascript">
> function fini()
> {
> alert("end");
> }
> function talk()
> {
> if (!('speechSynthesis' in window)) {
> alert("Unsupported browser");
> return;
> }
>
> alert("Getting ready.");
> var utterance = "Hello World";
> var chat = new SpeechSynthesisUtterance(utterance);
>
> chat.addEventListener('end', fini, false);
>
> speechSynthesis.speak(chat);
>
> }
> </script>
> </head>
> <body>
>
> <p>On Safari this example won't fire any known events<br />
> onend, onerror, even onended: -</p>
>
> <input type="button" value="Talk" onclick="talk()" />
> <br /><br />
> No probs on Chrome or Opera. Spewin!
> </body>
> </html>

On Safari is the button failing silently onclick? Is it not throwing an exception when it sees: "new SpeechSynthesisUtterance"? If it at least throw an error you could wrap with try..catch

Richard Maher

4/2/2015 1:19:00 AM

0

On 4/2/2015 7:53 AM, Andrew Poulos wrote:
> You realise that if you ever went for a job and the potential employer
> googled your name (assuming you are using your real name) then they'd
> probably view you, because of your "nasty" replies, with disdain.
>

Do you realize you are a knob?