/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { Action getCurrency = async delegate { var c = await this.GetConversionRate(); if (c.ContainsKey("GBP")) { Console.WriteLine(c["GBP"].ToString()); } Console.WriteLine(c.ToString()); var p = new IHTMLPre { innerText = c["GBP"].ToString()}; p.AttachTo(page.body); }; getCurrency(); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { var s = new IHTMLPre {innerText = 1234567L.ToCustomString()}; s.AttachTo(page.body); }
public Application(IApp page) { // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeTabsExperiment\ChromeTabsExperiment\Application.cs dynamic self = Native.self; dynamic self_chrome = self.chrome; object self_chrome_tabs = self_chrome.tabs; //if (self_chrome_tabs == null) // return; // ....488: { SourceMethod = Void.ctor(ChromeExtensionHopToTabThenShadow.HTML.Pages.IApp), i = [0x00ba] brtrue.s + 0 - 1 } //1984:02:01 RewriteToAssembly error: System.ArgumentException: Value does not fall within the expected range. //at jsc.ILInstruction.ByOffset(Int32 i) in X:\jsc.internal.git\compiler\jsc\CodeModel\ILInstruction.cs:line 1184 //at jsc.ILInstruction.get_BranchTargets() in X:\jsc.internal.git\compiler\jsc\CodeModel\ILInstruction.cs:line 1225 #region self_chrome_tabs if (self_chrome_tabs != null) { Console.WriteLine("self_chrome_tabs"); chrome.tabs.Updated += async (i, x, tab) => { // chrome://newtab/ if (tab.url.StartsWith("chrome-devtools://")) return; if (tab.url.StartsWith("chrome://")) return; // while running tabs.insertCSS: The extensions gallery cannot be scripted. if (tab.url.StartsWith("https://chrome.google.com/webstore/")) return; if (tab.status != "complete") return; //new chrome.Notification //{ // Message = "chrome.tabs.Updated " + new // { // tab.id, // tab.url, // tab.status, // tab.title // } //}; // while running tabs.insertCSS: The tab was closed. // public static Task<object> insertCSS(this TabIdInteger tabId, object details); // public static void insertCSS(this TabIdInteger tabId, object details, IFunction callback); // for some sites the bar wont show as they html element height is 0? await tab.id.insertCSS( new { code = @" html { border-left: 1em solid cyan; padding-left: 1em; } " } ); Console.WriteLine( "insertCSS done " + new { tab.id, tab.url } ); // where is the hop to iframe? // X:\jsc.svn\examples\javascript\Test\TestSwitchToIFrame\TestSwitchToIFrame\Application.cs // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201504/20150403 //await (HopToChromeTab)tab.id; await (HopToChromeTab)tab; //await tab.id; // are we now on the tab? // can we jump back? // what about jumping with files/uploads? Console.WriteLine("// are we now on the tab yet?"); Native.body.style.borderLeft = "1em solid blue"; Native.document.documentElement.style.borderLeft = "1em solid blue"; // <div class="player-video-title">Ariana Grande - One Last Time (Official)</div> Native.document.title = "(" + Native.document.title + ")"; // this is a shadow application var pre = new IHTMLPre { "shadow application. repackage the ui. root html element still displays borders." }; // AttachToDocumentShadow // see jsc, we are proposing a convinience method pre.AttachTo( Native.document.documentElement.shadow ); var div = new IHTMLDiv { }.AttachTo(pre); new IStyle(div) { // time to tell where we want our content // css breaks? cannot use this scenario yet. without rewriting css position = IStyle.PositionEnum.@fixed, //position = IStyle.PositionEnum.absolute, top = "3em", left = "0.5em", right = "0.5em", bottom = "0.5em" }; var content = new IHTMLContent { // show only the body //select = "body" }.AttachTo(div); // X:\jsc.svn\examples\javascript\xml\FindByClassAndObserve\FindByClassAndObserve\Application.cs // luckyly its only hidden... no need to await the element and find it later // <span id="eow-title" class="watch-title " dir="ltr" title="THORnews Weird Weather Watch! Wind Dragon inbound to USA Pacific Coast!"> //var yt0 = Native.document.querySelectorAll(" [class='player-video-title']"); //var yt1 = Native.document.querySelectorAll(" [class='watch-title ']"); //yt0.Concat(yt1).WithEach( // async e => // { // do // { // Native.document.title = e.innerText; // // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenShadow\ChromeExtensionHopToTabThenShadow\Application.cs // // we would need to jump back here to do extension notification // // the jump back would be to another state machine tho // // we would need other ports opened? // Native.document.documentElement.style.borderLeft = "1em solid yellow"; // for (int xi = 0; xi < 5; xi++) // { // Native.body.style.borderLeft = "1em solid yellow"; // await Task.Delay(100); // Native.body.style.borderLeft = "1em solid black"; // await Task.Delay(100); // } // Native.document.documentElement.style.borderLeft = "1em solid red"; // // or actually instead of jumping back we need to send back progress? // } // while (await e.async.onmutation); // } // ); // lets start monitoring }; return; } #endregion // we made the jump? Native.body.style.borderLeft = "1em solid red"; // yes we did. can we talk to the chrome extension? // lets do some SETI // The runtime.onMessage event is fired in each content script running in the specified tab for the current extension. // Severity Code Description Project File Line //Error 'runtime.onMessage' is inaccessible due to its protection level ChromeExtensionHopToTabThenShadow X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenShadow\ChromeExtensionHopToTabThenShadow\Application.cs 272 // public static event System.Action<object, object, object> Message #region chrome.runtime.Message chrome.runtime.Message += (object message, chrome.MessageSender sender, IFunction sendResponse) => { var s = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message; // 59ms onmessage {{ message = hello, id = aemlnmcokphbneegoefdckonejmknohh }} Console.WriteLine("xonmessage " + new { s.state, sender.id }); Native.body.style.borderLeft = "1px solid blue"; #region xAsyncStateMachineType var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault( item => { // safety check 1 //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName }); var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(item); if (xisIAsyncStateMachine) { //Console.WriteLine(new { item.FullName, isIAsyncStateMachine }); return item.FullName == s.TypeName; } return false; } ); #endregion var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType); var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine; var NewStateMachineI = (IAsyncStateMachine)NewStateMachine; #region 1__state xAsyncStateMachineType.GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).WithEach( AsyncStateMachineSourceField => { Console.WriteLine(new { AsyncStateMachineSourceField }); if (AsyncStateMachineSourceField.Name.EndsWith("1__state")) { AsyncStateMachineSourceField.SetValue( NewStateMachineI, s.state ); } } ); #endregion NewStateMachineI.MoveNext(); //Task.Delay(1000).ContinueWith( // delegate // { // sendResponse.apply(null, "response"); // } //); }; #endregion // Native.window.onmessage += e => //{ //}; }
public Application(IApp page) { // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeTabsExperiment\ChromeTabsExperiment\Application.cs dynamic self = Native.self; dynamic self_chrome = self.chrome; object self_chrome_tabs = self_chrome.tabs; #region self_chrome_tabs if (self_chrome_tabs != null) { Console.WriteLine("extension is now running..."); #region isYTMissing new { }.With( async delegate { var vid = "TXExg6Xj3aA"; var thumbnail = $"https://img.youtube.com/vi/{vid}/0.jpg"; var thumbnailImage = new IHTMLImage { src = thumbnail }; // wont get those events for 404? //Native.window.onerror += err => //{ // Console.WriteLine( // "window onerror " + // new // { // thumbnail, // err, // thumbnailImage.complete, // thumbnailImage.width, // thumbnailImage.naturalWidth, // thumbnailImage.naturalHeight // } // ); //}; //thumbnailImage.onerror += err => //{ // Console.WriteLine( // "thumbnailImage onerror " + // new // { // thumbnail, // err, // thumbnailImage.complete, // thumbnailImage.width, // thumbnailImage.naturalWidth, // thumbnailImage.naturalHeight // } // ); //}; await thumbnailImage.async.oncomplete; Console.WriteLine( new { thumbnail, thumbnailImage.complete, thumbnailImage.width, thumbnailImage.naturalWidth, thumbnailImage.naturalHeight } ); var thumbnailBytes = await thumbnailImage.async.bytes; Console.WriteLine( new { thumbnailBytes.Length } ); // crc? var sw = Stopwatch.StartNew(); var crc = CRCExample.ActionScript.Crc32Helper.GetCrc32(thumbnailBytes); // 247ms {{ crc = 9e47636d, ElapsedMilliseconds = 7 }} var isYTMissing = 0x9e47636d == crc; Console.WriteLine( new { crc = crc.ToString("x8"), sw.ElapsedMilliseconds, isYTMissing } ); } ); #endregion var oncePerTab = new Dictionary<TabIdInteger, object>(); chrome.tabs.Updated += async (i, x, tab) => { // chrome://newtab/ // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201504/20150423 #region tab if (tab == null) { Console.WriteLine("bugcheck :198 iframe? called with the wrong state?"); return; } Console.WriteLine("enter async chrome.tabs.Updated " + new { tab.url, tab.status }); if (tab.url.StartsWith("chrome-devtools://")) { return; } if (tab.url.StartsWith("chrome://")) return; // while running tabs.insertCSS: The extensions gallery cannot be scripted. if (tab.url.StartsWith("https://chrome.google.com/webstore/")) return; if (tab.status != "complete") { Console.WriteLine("exit async chrome.tabs.Updated, not complete?"); return; } #endregion if (oncePerTab.ContainsKey(tab.id)) return; oncePerTab[tab.id] = new object(); // where is the hop to iframe? // X:\jsc.svn\examples\javascript\Test\TestSwitchToIFrame\TestSwitchToIFrame\Application.cs // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201504/20150403 //await (HopToChromeTab)tab.id; Console.WriteLine("chrome.tabs.Updated will delay, to increment state"); // why do we need this fake await? // cannot resume state otherwise? await Task.Delay(1); // // X:\jsc.svn\market\synergy\javascript\chrome\chrome\chrome.idl var tabIdString = Convert.ToString((object)tab.id); // 13032ms chrome.tabs.Updated will HopToChromeTab {{ tabIdString = 608 }} Console.WriteLine("chrome.tabs.Updated will HopToChromeTab " + new { tabIdString }); // state1: await (HopToChromeTab)tab; // TypeError: Cannot set property 'ztabIdString' of null ztabIdString = tabIdString; //await tab.id; // are we now on the tab? // can we jump back? // 531ms yt found {{ Length = 108 }} // X:\jsc.svn\examples\javascript\test\TestShadowForIFrame\TestShadowForIFrame\Application.cs //var yt1 = Native.document.querySelectorAll(" [class='youtube-player']"); // <iframe width="420" height="315" src="https://www.youtube.com/embed/sJIh70IZua8" frameborder="0" allowfullscreen=""></iframe> // 503ms create iframe... {{ ztabIdString = null }} // what about jumping with files/uploads? Console.WriteLine("create iframe... " + new { ztabIdString }); iframe = new IHTMLIFrame { //src = "about:blank" //new XElement("button", "did extension send us our code? " ) new XElement("script", new XAttribute("src", url), " ") }.AttachTo( Native.document.documentElement ); var yt1 = Native.document.querySelectorAll("iframe"); Console.WriteLine("yt found " + new { yt1.Length }); yt1.WithEach( async e => { //if (e == null) // return; var xiframe = (IHTMLIFrame)e; //13ms yt found { { Length = 9 } } //VM1190: 51533 515ms enter catch //{ // mname = < 01ed > ldloca.s.try } ClauseCatchLocal: // VM1190: 51533 515ms TypeError: Cannot read property 'src' of null if (!xiframe.src.StartsWith("https://www.youtube.com/")) { return; } // can we interact, swap the videos? var size = new { xiframe.clientWidth, xiframe.clientHeight }; var swap = new IHTMLDiv { //new IHTMLPre { xiframe.src }, //new IHTMLContent { } }; new IStyle(swap) { backgroundColor = "yellow", width = size.clientWidth + "px", height = size.clientHeight + "px", overflow = IStyle.OverflowEnum.hidden }; // https://code.google.com/p/dart/issues/detail?id=19561 // 27ms HierarchyRequestError: Failed to execute 'createShadowRoot' on 'Element': Author-created shadow roots are disabled for this element. //swap.AttachTo(xiframe.shadow); xiframe.ReplaceWith(swap); var sh = new IHTMLDiv { }.AttachTo(swap.shadow); var vid = xiframe.src.TakeUntilIfAny("?").SkipUntilOrEmpty("/embed/"); // Remote Address:[2a00: 1450:400f:802::100e]:443 //Request URL: https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg //Request Method: GET //Status Code: 404 OK var thumbnail404 = $"https://img.youtube.com/vi/{vid}/0.jpg"; // lets look at the image. is the video removed? // https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg // http://stackoverflow.com/questions/22097747/getimagedata-error-the-canvas-has-been-tainted-by-cross-origin-data //.AttachToHead(); new IStyle(sh) { width = size.clientWidth + "px", height = size.clientHeight + "px", overflow = IStyle.OverflowEnum.hidden, position = IStyle.PositionEnum.relative, backgroundImage = $"url('{thumbnail404}')", }; //var info = new IHTMLPre { xiframe.src }; var info = new IHTMLPre { new { vid } }; // so we can later find it again... lookup_info[thumbnail404] = info; // assume its not missing until we know more lookup_info_YTmissing[thumbnail404] = false; info.AttachTo(sh); new IStyle(info) { backgroundColor = "rgba(0,0,255, 0.5)", color = "rgba(255,255,0, 0.9)", left = "0px", bottom = "0px", right = "0px", //height = size.clientHeight + "px", position = IStyle.PositionEnum.absolute }; // at this point we need to consult the extension as it can download the bytes new { }.With( async delegate { var xtabIdString = ztabIdString; var xthumbnail404 = thumbnail404; // 517ms about to jump to extension to inspect the damn image... {{ xthumbnail404 = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, xtabIdString = 608 }} Console.WriteLine("about to jump to extension to inspect the damn image... " + new { xthumbnail404, xtabIdString }); // fixup? await Task.Delay(1); await default(HopToExtension); Console.WriteLine("about to jump to extension to inspect the damn image... done " + new { xthumbnail404, xtabIdString }); // 43228ms about to jump to extension to inspect the damn image... done {{ xthumbnail404 = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, xtabIdString = 608 }} // can we jump back once we know what it was? var thumbnailImage = new IHTMLImage { src = xthumbnail404 }; await thumbnailImage.async.oncomplete; var thumbnailBytes = await thumbnailImage.async.bytes; var sw = Stopwatch.StartNew(); var crc = CRCExample.ActionScript.Crc32Helper.GetCrc32(thumbnailBytes); // we only do strings at this point, not integers, we could do booleans tho... var isYTMissing = Convert.ToString(0x9e47636d == crc); var xtab = await chrome.tabs.get(tabId: Convert.ToInt32(xtabIdString)); //xthumbnail404 = https://img.youtube.com/vi/BZIeqnQ1rY0/0.jpg, isYTMissing = false, xtabIdString = 608, url = https://zproxy.wordpress.com/2015/04/05/thought-form-magicians/ }} // xthumbnail404 = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, isYTMissing = true, xtabIdString = 608, url = https://zproxy.wordpress.com/2015/04/05/thought-form-magicians/ }} Console.WriteLine(">> " + new { xthumbnail404, isYTMissing, xtabIdString, xtab.url }); // can we jump back to the tab to color it red if missing? // 43340ms >> {{ xthumbnail404 = https://img.youtube.com/vi/TXExg6Xj3aA/0.jpg, isYTMissing = true, xtabIdString = 608 }} //(HopToChromeTab) // ok now we now what tab we are in but even if we jump back. we wont have a ref to the infobar? await (HopToChromeTab)xtab; Console.WriteLine(">> " + new { xthumbnail404, isYTMissing, xtabIdString } + " back in the tab?"); // would the old variables be reconnected for us? // jumps should be able to resume an old startemachine. lookup_info_YTmissing[xthumbnail404] = Convert.ToBoolean(isYTMissing); var xinfo = lookup_info[xthumbnail404]; //xthumbnail404 = https://img.youtube.com/vi/BZIeqnQ1rY0/0.jpg, isYTMissing = false, xtabIdString = 744 }} back in the tab? if (Convert.ToBoolean(isYTMissing)) { // yikes. video pulled! new IStyle(xinfo) { backgroundColor = "rgba(255,0,0, 0.7)", }; new IHTMLSpan { " do we have a local copy?" }.AttachTo(xinfo); // we should send udp to the archive server? // if it has how can we load it up? return; } new IStyle(xinfo) { backgroundColor = "rgba(255,255,0, 0.5)", }; } ); // https://www.youtube.com/embed/jQLNMljadyo?vers // https://www.youtube.com/embed/M4RBW85J4Cg // http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg await sh.async.onmouseover; // no reason to load it. its missing! if (lookup_info_YTmissing[thumbnail404]) return; xiframe.AttachTo(sh); info.AttachTo(sh); var copyToToolbar = new IHTMLButton { "+" }.AttachTo(info); await copyToToolbar.async.onclick; copyToToolbar.Orphanize(); //width = "128px", //xiframe.style.transform = "scale(0.2)"; new IStyle(xiframe) { width = (128) + "px", height = (96) + "px", }; // This video contains content from WMG. It is restricted from playback on certain sites. xiframe.AttachTo( //iframe.contentWindow.document.documentElement iframe.contentWindow.document.body ); } ); Console.WriteLine("create iframe... done"); //iframe.allowTransparency = true; // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201504/20150423 // __8__1 is null. why? a struct? // b.__this.__8__1.scope = new ctor$vQEABrCB_bTmuL0jGQp_bnVw(b.__this._iframe_5__2); // oh crap. the container is initialized before await (HopToChromeTab)tab; thus lost due to context switch. var scope = new { iframe }; //Console.WriteLine("iframe visible? " + new { scope }); new IStyle(iframe) { borderWidth = "0", // wont animate? transition = "left 300ms linear", // dont want the white box while it loads.. backgroundColor = "rgba(0, 0, 255, 0)", position = IStyle.PositionEnum.@fixed, //left = "1px", top = "32px", width = "128px", // animateIFrame // pre hide it left = "-120px", //height = "100px", // wont work on slashdot? //bottom = "3em" // can we be topmost? //zIndex = 30000 zIndex = 1999999999 }; fixHeight(iframe); animateIFrame(iframe); //var __iframe = iframe; await iframe.async.onload; //new IStyle(iframe) //{ // backgroundColor = "rgba(0, 0, 255, 0.7)", //}; Console.WriteLine("lets hop from tab context to iframe context... "); await (HopToIFrame)iframe; Console.WriteLine("lets hop from tab context to iframe context... done!"); new IStyle(Native.document.body) { margin = "0px", //marginRight = "1em", padding = "0px", paddingRight = "1em", transition = "background-color 300ms linear", backgroundColor = "rgba(0, 0, 255, 0.1)", //border = "1px solid red" }; var button4 = new IHTMLButton { "hop to parent, extension, app" }.AttachToDocument(); new IStyle(button4) { display = IStyle.DisplayEnum.block }; // not yet. need a new example button4.disabled = true; //Native.body.backgroundColor = "rgba(0, 0, 255, 0.7)"; //var text3 = new IHTMLTextArea { value = "hey" }.AttachToDocument(); // need to use static, as scope variables are being encapsulated, and due to context jumps we dont support it yet text3 = new IHTMLTextArea { value = "hey" }.AttachToDocument(); text3.style.width = "100%"; var button3 = new IHTMLButton { "hop to parent, extension" }.AttachToDocument(); new IStyle(button3) { display = IStyle.DisplayEnum.block }; button3.onclick += async delegate { // can we hop back? var data3 = text3.value; Console.WriteLine("enter button3 " + new { data3 }); // 2602ms enter button3 {{ data3 = hey }} // why do we need this fake await? // cannot resume state otherwise? await Task.Delay(1); await default(HopToParent); var tab_title = Native.document.title; // 3105ms are strings being synchronized to iframe? {{ tab_title = IANA — IANA-managed Reserved Domains, data3 = null }} Console.WriteLine("are strings being synchronized from iframe? " + new { tab_title, data3 }); /// 2926ms will hop back to extension!? can we resume later? await default(HopToExtension); //Native.window.alert("hi! i am back home! do we even know which tab we were in? did i get some data yet? " + new { tab_title }); Console.WriteLine("hi! i am back home! do we even know which tab we were in? did i get some data yet? " + new { tab_title, data3 }); // 13844ms hi! i am back home! do we even know which tab we were in? did i get some data yet? {{ tab_title = IANA — IANA-managed Reserved Domains }} // lets guess which tab we clicked on? var tt = await chrome.tabs.getCurrent(); // https://developer.chrome.com/extensions/tabs // https://developer.chrome.com/extensions/windows // https://developer.chrome.com/extensions/processes //chrome.runtime. new chrome.Notification( title: new { data3, tt }.ToString() ); //chrome.tabs.rel // can we do appwindow here or we need to jump out of extension? }; var button2 = new IHTMLButton { "hop to parent" }.AttachToDocument(); new IStyle(button2) { display = IStyle.DisplayEnum.block }; button2.onclick += async delegate { // can we hop back? Console.WriteLine("enter button2"); // why do we need this fake await? // cannot resume state otherwise? await Task.Delay(1); await default(HopToParent); var tab_title = Native.document.title; Console.WriteLine("are strings being synchronized to iframe? " + new { tab_title }); // we are jumping back, yet into a new state machine. //Native.window.alert("hi! in a tab, in an extension! " + new //{ // Native.document.title // , // iframe //}); // can we jump back? is the iframe awaiting for multiple jumps? await (HopToIFrame)iframe; Native.window.alert("hi! iframe, in a tab, in an extension! " + new { Native.document.title, tab_title }); // ok. we now know how to // jump from extension to tab to iframe to tab to iframe // what about workers, and jumping back to extension? // but likely we did not jump to the same data? }; var button1 = new IHTMLButton { "click me" }.AttachToDocument(); new IStyle(button1) { display = IStyle.DisplayEnum.block }; //new { }.With( // async delegate // { // // stack variables not visible, why? // while (await button1.async.onmouseover) // { // new IStyle(Native.document.body) // { // backgroundColor = "rgba(0, 0, 255, 0.8)", // }; // await button1.async.onmouseout; // new IStyle(Native.document.body) // { // backgroundColor = "rgba(0, 0, 255, 0.2)", // }; // } // } //); //oldschool as a workaround button1.onclick += delegate { Native.window.alert("hi! iframe, in a tab, in an extension! " + new { Native.document.title }); }; button1.onmouseover += e => { new IStyle(Native.document.body) { backgroundColor = "rgba(255, 0, 0, 0.9)", }; e.stopPropagation(); }; button1.onmouseout += delegate { new IStyle(Native.document.body) { backgroundColor = "rgba(0, 0, 255, 0.1)", }; }; // we are in iframe! Native.document.onmouseover += delegate { new IStyle(Native.document.body) { backgroundColor = "rgba(0, 0, 255, 0.3)", }; }; Native.document.onmouseout += delegate { new IStyle(Native.document.body) { backgroundColor = "rgba(0, 0, 255, 0.1)", }; }; //var f = new IHTMLButton { "in the frame! click to notify parent" }.AttachToDocument(); //await default(HopToParent); // why need this stackfix? //var stackfix_iframe = iframe; // new { }.With( // async delegate // { // while (await Native.window.async.onresize) // { // stackfix_iframe.style.height = (Native.window.Height - 64) + "px"; // } // } //); // X:\jsc.svn\examples\javascript\Test\TestHopFromIFrame\TestHopFromIFrame\Application.cs // can we jump? // <div class="player-video-title">Ariana Grande - One Last Time (Official)</div> //Native.document.title = "(" + Native.document.title + ")"; // X:\jsc.svn\examples\javascript\xml\FindByClassAndObserve\FindByClassAndObserve\Application.cs // luckyly its only hidden... no need to await the element and find it later // <span id="eow-title" class="watch-title " dir="ltr" title="THORnews Weird Weather Watch! Wind Dragon inbound to USA Pacific Coast!"> //var yt0 = Native.document.querySelectorAll(" [class='player-video-title']"); //var yt1 = Native.document.querySelectorAll(" [class='watch-title ']"); //yt0.Concat(yt1).WithEach( // async e => // { // do // { // Native.document.title = e.innerText; // // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs // // we would need to jump back here to do extension notification // // the jump back would be to another state machine tho // // we would need other ports opened? // Native.document.documentElement.style.borderLeft = "1em solid yellow"; // for (int xi = 0; xi < 5; xi++) // { // Native.body.style.borderLeft = "1em solid yellow"; // await Task.Delay(100); // Native.body.style.borderLeft = "1em solid black"; // await Task.Delay(100); // } // Native.document.documentElement.style.borderLeft = "1em solid red"; // // or actually instead of jumping back we need to send back progress? // } // while (await e.async.onmutation); // } // ); // lets start monitoring }; return; } #endregion // 420ms TypeError: Cannot read property 'url' of null Console.WriteLine("nop"); #if true #region inside iframe if (Native.window.parent != Native.window) { // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs // inside iframe new { }.With( async delegate { // start the handshake // we gain intellisense, but the type is partal, likely not respawned, acivated, initialized //var m = await Native.window.parent.postMessageAsync<TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine>(); // new IHTMLPre { // "inside iframe awaiting onmessage" //}.AttachToDocument(); // first null jump //Native.window.parent.postMessage(r.shadowstate); var m = await Native.window.parent.postMessageAsync(default(TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)); Console.WriteLine("iframe got the first state..."); // we can now send one hop back? InternalInvoke(m.data); } ); return; } #endregion #endif Console.WriteLine("nop"); // we made the jump? //Native.body.style.borderLeft = "0em solid red"; // yes we did. can we talk to the chrome extension? // lets do some SETI // The runtime.onMessage event is fired in each content script running in the specified tab for the current extension. // Severity Code Description Project File Line //Error 'runtime.onMessage' is inaccessible due to its protection level ChromeExtensionHopToTabThenIFrame X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs 272 // public static event System.Action<object, object, object> Message Action<object> PostToExtension = null; #region Connect chrome.runtime.Connect += port => { Console.WriteLine("chrome.runtime.Connect " + new { port.name, port.sender }); // 8295ms will invoke sendResponse... done?? {{ message = jump! }} //port.postMessage("jump! " + new { port.name, port.sender }); PostToExtension = xdata => { // PostToExtension {{ xdata = [object Object] }} Console.WriteLine("PostToExtension " + new { xdata }); //Console.WriteLine("PostToExtension " + new { xdata = JSON.stringify(xdata) }); port.postMessage(xdata); }; }; #endregion #region chrome.runtime.Message chrome.runtime.Message += (object message, chrome.MessageSender sender, IFunction sendResponse) => { var s = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message; if (url != null) { Console.WriteLine("jumping back to tab for more? done"); InternalInvoke(s); return; } Console.WriteLine("chrome.runtime.Message " + new { s.state, sender.id, code = s.code.Length }); // at this point we can initialize hop to iframe since we have the code we can actually use? // 276ms xonmessage {{ state = 1, id = fkgibadjpabiongmgoeomdbcefhabmah, code = 3296612 }} #region url var aFileParts = new[] { s.code }; var oMyBlob = new Blob(aFileParts, new { type = "text/javascript" }); //var url = oMyBlob.ToObjectURL(); url = URL.createObjectURL(oMyBlob); #endregion Console.WriteLine("will we want to jump back to extension?"); HopToExtension.VirtualOnCompleted += (that, continuation) => { Console.WriteLine("will hop back to extension!? can we resume later?"); var r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation); // can we only send once? //Console.WriteLine("will invoke sendResponse... " + new { sendResponse }); Console.WriteLine("will invoke sendResponse... "); //sendResponse.apply(null, r); //will invoke sendResponse... //(program):51533 1664ms enter catch //{ // mname = < 0154 > ldarg.0.try } ClauseCatchLocal: // (program):51533 1664ms TypeError: Converting circular structure to JSON // planB PostToExtension(r.shadowstate); }; InternalInvoke(s); //Task.Delay(1000).ContinueWith( // delegate // { // sendResponse.apply(null, "response"); // } //); }; #endregion // Native.window.onmessage += e => //{ //}; }