Clear Filters
Clear Filters

Access details of dynamically-created web content in Matlab's browser

8 views (last 30 days)
Is there any way to access the properties of dynamically-created objects (specifically, an SVG canvas created via a D3.js script) that are rendered on load in the Matlab browser? Perhaps some way to diving into the web browser handle returned by web?
I currently deal with this by passing the .html file in question through phantomJS (wait for render to finish and extract the svg element to a file), but I'm hoping to find a solution that doesn't require end users to install phantomJS themselves.

Answers (1)

Kelly Kearney
Kelly Kearney on 5 Dec 2016
Tech support pointed me to the answer to this one. In newer releases of Matlab, the HtmlText property of a web browser handle is updated dynamically the displayed page is run. In my case, I had my javascript code add a specific div element to the page once it had completed its calculations. In Matlab, I could keep querying the html text every second or so, and look for the text of that div.
[stat, h] = web('index.html');
% Wait for the user to check the DONE box, then dump the html from the
% browser into a file
while ~checkstatus(h)
pause(1);
end
txt = get(h, 'HtmlText');
close(h);
function isdone = checkstatus(h)
txt = get(h, 'HtmlText');
if isempty(txt)
isdone = false;
else
idx1 = strfind(txt, '<div id="textparams">');
if isempty(idx1)
isdone = false;
else
idx2 = strfind(txt, '</div>');
idx2 = idx2(find(idx2 > idx1,1)) + 6;
divtext = txt(idx1:idx2);
isdone = ~isempty(strfind(divtext, 'DONE'));
end
end

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!