Skip to content

Commit

Permalink
Fix bug with some image srcs, add test links
Browse files Browse the repository at this point in the history
  • Loading branch information
TetraTsunami committed Jun 4, 2024
1 parent 13704d0 commit 4dfa8ca
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/background/index.chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { installedHandler, mergeMeta } from './background';

const metaFromHTML = (html: string, url: string) => {
const doc = (new JSDOM(html)).window.document

let baseEl = doc.createElement('base'); // https://stackoverflow.com/questions/55232202/optional-baseuri-location-in-domparser
baseEl.setAttribute('href', url);
doc.head.append(baseEl);
const title = (doc.querySelector('meta[property="og:title"]') as HTMLMetaElement)?.content ||
doc.querySelector('title')?.textContent;
const description = (doc.querySelector('meta[property="og:description"]') as HTMLMetaElement)?.content ||
Expand Down
6 changes: 4 additions & 2 deletions src/background/index.firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { getFirstImage, type Meta } from "./parsing";
import { installedHandler, mergeMeta } from './background';

const metaFromHTML = (html: string, url: string) => {
const doc = (new DOMParser()).parseFromString(html, 'text/html')

const doc = new DOMParser().parseFromString(html, 'text/html')
let baseEl = doc.createElement('base'); // https://stackoverflow.com/questions/55232202/optional-baseuri-location-in-domparser
baseEl.setAttribute('href', url);
doc.head.append(baseEl);
const title = (doc.querySelector('meta[property="og:title"]') as HTMLMetaElement)?.content ||
doc.querySelector('title')?.textContent;
const description = (doc.querySelector('meta[property="og:description"]') as HTMLMetaElement)?.content ||
Expand Down
54 changes: 54 additions & 0 deletions tests/problem-pages.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #2b2a33;
color: #fff;
}
a {
color: #fff;
text-decoration: underline;
}
table {
margin: 0 auto;
border-collapse: collapse;
}
th, td {
padding: 4px 10px;
text-align: center;
border: 1px solid #fff;
}
</style>
</head>
<body>
<table>
<tr>
<th>Link</th>
<th>Hover</th>
<th>Action</th>
</tr>
<tr>
<td><a href="https://www.theverge.com/2019/5/21/18634195/t-mobile-sprint-merger-conditions-access-coverage">Website with OpenGraph</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td><a href="https://tsuni.dev">Website without OpenGraph</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td><a href="https://tree-diffusion.github.io/">SPA whose base markup is empty</a></td>
<td></td>
<td></td>
</tr>
<tr>
<td><a href="https://hutchesonlab.fiu.edu/wp-content/uploads/sample-pdf.pdf">Non-HTML Page</a></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>

0 comments on commit 4dfa8ca

Please sign in to comment.