cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Memorable Member
Memorable Member

Web.Page question

Hello Power BI developers team,

I realized that javascript executes inside Power query through Web.Page like following

 

let
    Source = Web.Page(
        "<script>
        var square = function (x){return x*x;};
        var c = square(12);
      document.write(c);          
        </script>"),
    Data = Source{0}[Data],
    Children = Data{0}[Children],
    #"Expanded Children" = Table.ExpandTableColumn(Children, "Children", {"Kind", "Name", "Children", "Text"}, {"Kind.1", "Name.1", "Children.1", "Text.1"})
in
    #"Expanded Children"

 

But there are certain things that don't. For e.g. var square changed to const square in the above exmaple

 

let
    Source = Web.Page(
        "<script>
        const square = function (x){return x*x;};
        var c = square(12);
      document.write(c);          
        </script>"),
    Data = Source{0}[Data],
    Children = Data{0}[Children],
    #"Expanded Children" = Table.ExpandTableColumn(Children, "Children", {"Kind", "Name", "Children", "Text"}, {"Kind.1", "Name.1", "Children.1", "Text.1"})
in
    #"Expanded Children"

 

One more example of non-execution

 

//doesnot execute
let
    Source = Web.Page(
        "<script>
        var obj = {foo:'bar,baz:'42'};
        var values = Object.keys(obj);
      document.write(values);          
        </script>"),
    Data = Source{0}[Data],
    Children = Data{0}[Children],
    Children1 = Children{0}[Children]
in
    Children1

 

I have tried with few and some syntax excutes while other don't.

E.g. Regex positive lookbehind does not work

 

/(?<=[a-zA-Z]+[/]+[a-zA-Z]+[ ])\d+/gm

 

but negative  lookahead works.

 

/\d+(?![a-zA-Z]+[/]+[a-zA-Z]+[ ])/gm

 

String

 

123INVOICE 7320210279

 

Rather than trying to figure out which works and which doesn't is it kindly possible to advise which javascript excution engine is used inside PQWRY. Is it equivalent to an engine <IE9?

If I can have this infomration I can either tune my script to match the version or not use the syntax at all.

Many thanks in advance.

 

 

 


New Animated Dashboard: Sales Calendar


1 ACCEPTED SOLUTION
Super User III
Super User III

Hi @smpa01 

If you create a Web request to a browser testing website like WhatIsMyBrowser.com or Cyscape.com then you can get info about the browser used within PQ.  For example, my PBI Desktop reports it is using IE 11

browser1.png

 

browser2.png

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

6 REPLIES 6
Super User III
Super User III

Hi @smpa01 

If you create a Web request to a browser testing website like WhatIsMyBrowser.com or Cyscape.com then you can get info about the browser used within PQ.  For example, my PBI Desktop reports it is using IE 11

browser1.png

 

browser2.png

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

@PhilipTreacy  many thanks for this. It definitely saves me a lot of time. 

 

I am still having problem running js syntax inside PQ that has full support in IE11. E.g. Object.keys has full support in IE11.

https://caniuse.com/?search=object.keys

 

let
    Source = Web.Page(
        "<script>
        var obj = {foo:'bar,baz:'42'};
        var values = Object.keys(obj);
      document.write(values);          
        </script>"),
    Data = Source{0}[Data],
    Children = Data{0}[Children],
    Children1 = Children{0}[Children]
in
    Children1

 

 I don't know why is that.

 

@lbendlin 

How do you get your script to accept external parameters? - will do a blogpost

 

What can Javascript do that M can't ? - will do a blogpost .

For starter, REGEX can be natively run in PQ rather than running it through R's stringr (R libraries can't be run in service which is extremely painful, if you have a lot of REGEX wrangling).

Secondly, Different complex Looping for difficult data wranglings.

Once I figure out which syntax and function can be run in PQ , the full power of js (limited to PQ's browser version) can be unleashed for tasks that were thought out of reach in PQ.


New Animated Dashboard: Sales Calendar


Hi @smpa01 

I'd be surprised if the browser engine inside PQ is actually a full implementation of IE11.  The browser test sites probably identify IE11 by the user agent string.  Sorry I can't shed any more light on this.

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


@PhilipTreacy  Many thanks for your time.


New Animated Dashboard: Sales Calendar


Super User III
Super User III

this is a nice find  (and you should be able to infer the rendering engine from the windows task manager) but what's the business value of this? How do you get your script to accept external parameters?  What can Javascript do that M can't ?

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Microsoft Ignite

Microsoft Ignite with Arun Ulag

Featured Session Drive Data Culture with Power BI: Vision, Strategy & Roadmap. Register here https://myignite.microsoft.com #MSIgnite #PowerPlatform #Power BI ​

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors