Bug 4879
| Summary: | Included Javascript included in a page loaded with [WebFrame loadHTMLString:] is ignored | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Dan Wood <dwood> |
| Component: | JavaScriptCore | Assignee: | Maciej Stachowiak <mjs> |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | Normal | CC: | mitz, timber, ttalbot |
| Priority: | P2 | ||
| Version: | 420+ | ||
| Hardware: | Mac | ||
| OS: | OS X 10.4 | ||
Dan Wood
If your webview is populated from [WebFrame loadHTMLString:] instead of [WebFrame loadRequest:],
then javascript that is included (e.g. <script src='http://....' />) is ignored.
Steps to reproduce:
* Launch SnippetEditor (Apple Sample Code)
* Paste in the following lines:
<html><body><h1>Weather</h1>
<script src='http://voap.weather.com/weather/oap/94501?
template=HOMEV&par=null&unit=0&key=dee4cdf9e236b73c2cca35ff802a0339'></script>
</body></html>
* Click Button: Update from Text
Expected Results: you should see the headline and a weather.com display
Actual result: You only see the headline
Notes: If you save the above snippet to a file, specify the URL of that file, and then do "Update from
URL", you *will* see the weather information.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Colin Barrett
I'm interested in looking at this. Later in the week, probably. Lost & Invasion
are on tonight ;-)
James Howard
This seems to be fixed in WebKit version 420+ (current cvs).
Dan Wood
I just checked with TOT as of 11/17/05 and my test case still fails. I believe that the bug is still a real
bug.
Dan Wood
Whoops, you're right, my test case does work now with TOT. However I still seem to be having related
problems with Sandvox which is supposed to be doing the same thing, so I may have to create a new test
case.
Dan Wood
OK, here's a new test case that shows the problem in TOT 11/17/05.
In SnippetEditor, paste in the following lines:
<html>
<head>
</head>
<body>
<h1>Apple hot news feed</h1>
<script src="http://service.karelia.com/feed.js.php?url=http://www.apple.com/main/rss/hotnews/
hotnews.rss&h=oEPs7zbjQNvNVMqi6eooSO1AuCA=&max=99&k=c79e4f32899dbb4758
96e72281be7f8217eaa211" type="text/javascript" />
<p>END</p>
</body>
Click "Update from Text" button.
RESULTS:
No output from the script is included in the page generated.
ANALYSIS:
The delay indicates to me that the javascript is actually executed, but it is as if the output generated is
not being put into the page's output stream.
Pasting that same HTML into a test.html file and loading it from Safari, the JavaScript outputs just fine.
NOTE:
You can see the javascript that should be inserted into the output stream with CURL (after de-escaping
the &s in the URL to load:
curl -i "http://service.karelia.com/feed.js.php?url=http://www.apple.com/main/rss/hotnews/
hotnews.rss&h=oEPs7zbjQNvNVMqi6eooSO1AuCA=&max=99&k=c79e4f32899dbb475896e72281be7f
8217eaa211"
mitz
The problem here is that in the loadHTMLString case, the loader decodes the script source as UTF-16
instead of ISO-8859-1.
An easy workaround is to add specify the charset in the <script> tag. E.g., this works in the snippet
editor:
<html>
<head>
</head>
<body>
<h1>Apple hot news feed</h1>
<script src="http://service.karelia.com/feed.js.php?url=http://www.apple.com/main/rss/hotnews/
hotnews.rss&h=oEPs7zbjQNvNVMqi6eooSO1AuCA=&max=99&k=c79e4f32899dbb4758
96e72281be7f8217eaa211" type="text/javascript" charset="ISO-8859-1"/>
<p>END</p>
</body>
mitz
Another possible workaround is instead of -loadHTMLString:baseURL: to use -
loadData:MIMEType:textEncodingName:baseURL: with data in the same encoding as you expect the script
to be in.
I'm not sure this is a bug.
Dan Wood
I filed a documentation bug on Radar <rdar://4349353> after some discussion with mitzpettel about
how best to avoid this problem for future developers!
Dan Wood
*** This bug has been marked as a duplicate of 5140 ***